I want to use some tools during build that are acquired with nuget. Here is relevant part of csproj file:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
</GetAssemblyIdentity>
<Exec Command="nuget pack MyApp.nuspec -Version %(myAssemblyInfo.Version) -Properties Configuration=Release -OutputDirectory bin\Release -BasePath bin\Release" />
<Exec Command="squirrel --no-msi --releasify bin\Release\MyApp.%(myAssemblyInfo.Version).nupkg" />
</Target>
Namely I want to use Squirrel and NuGet itself (contained in NuGet.CommandLine package) to build an installer. Executables are located in packages\<package name>\tools\*.exe. The lines used in Exec command work in Package Manager Console but Visual Studio can't find the executables during build (error 9009). It there a way to include package tools in current path during build to make them available?
Related
A have a .NET Core project and i want to copy a specified NuGet reference (assembly.dll) to the build output because i'm using a dependency injection component that searches de bin folder for the types.
I know that i could use this, but it copies all the nugets when I only want a specific nuget package to be copied:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
Assuming you're using Visual Studio...
Project->Properties->Build Events
"Put this in the Post-build event command line:" box
copy "$(SolutionDir)assembly.dll" "$(TargetDir)"
Or add this to your project file:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy "$(SolutionDir)assembly.dll" "$(TargetDir)"" />
</Target>
I'm trying to build a project with NSwagger installed.
Here is my .csporj configuration:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\NSwag.MSBuild.11.15.3\build\NSwag.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NSwag.MSBuild.11.15.3\build\NSwag.MSBuild.props'))" />
</Target>
<Target Name="BeforeBuild">
<Exec Command="$(NSwagExe) run $(SolutionDir)webapi.nswag" />
</Target>
Error :
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "C:\agent_work\8\s\Web\CSU.Marketplace.Web.sln" (1) is building "C:\agent_work\8\s\Web\CSU.Marketplace.Web\CSU.Marketplace.Web.csproj" (2) on node 1 (default targets).
BeforeBuild:
run C:\agent_work\8\s\Web\webapi.nswag
'run' is not recognized as an internal or external command,
operable program or batch file.
Web\CSU.Marketplace.Web\CSU.Marketplace.Web.csproj(942,5): Error MSB3073: The command " run C:\agent_work\8\s\Web\webapi.nswag" exited with code 9009.
The project file does not import the NSwag build tasks.
Therefore at build time, $(NSwagExe) expands to an empty string, and msbuild tries to run the rest of the command:
run C:\agent_work\8\s\Web\webapi.nswag
Add something like this:
<ItemGroup>
<PackageReference Include="NSwag.MSBuild" Version="11.12.9" />
</ItemGroup>
I can't make it work TFS build. It is nuget restore issue. Nuget is not restoring reference dll files.
Here is belwo my build configuration. Please advise me how I can make this works.
As per this blog post on Nuget's website you can use the command line you mentioned, but it has to be part of a custom target using a Build.proj file.
You need to add a Build.proj and put this as the contents:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)src\</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(SourceHome)*.sln">
<AdditionalProperties>OutDir=$(OutDir);Configuration=$(Configuration)</AdditionalProperties>
</Solution>
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Clean">
<MSBuild Targets="Clean"
Projects="#(Solution)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="#(Solution)" />
</Target>
<Target Name="Rebuild" DependsOnTargets="RestorePackages">
<MSBuild Targets="Rebuild"
Projects="#(Solution)" />
</Target>
</Project>
Alternatively, you could call it from a custom Pre-Build Script.
Or, customise the XAML template and add a Foreach loop to invoke:
nuget.exe restore path\to\solution.sln
on each solution in the build definition.
Here are some steps (described here which was mentioned in Dave's post) you need to follow in order to have these NuGet packages restored during the VSO (TFS) build process.
Add following items to the solution. (Content of the nuget.config and .tfignore file can be found here)
Add one build.proj file under the root path of the solution folder. (Content of the build.proj file can be found here)
Create one folder named tools under the root path of the solution folder. Create NuGet sub-folder under tools folder, download and save nuget.exe under tools\NuGet path.
Check in nuget.config, .tfignore, build.proj and tools\NuGet\nuget.exe into TFS version control.
Modify the build definition to choose to build the build.proj file.
Then you will have NuGet packages restored successfully during the TFS build process.
I'm trying to upgrade our TFS server to 2013. We're currently using 2012, but we've also been clinging on to the upgrade template for dear life. With 2013, we'd like to go to the default template and modify it as little as possible.
The problem comes in when you consider that the default template asks you to add each individual .csproj or .sln file that you would like to build. The nice thing about the tfsbuild.proj files is that not only can you build on the server, but you can check out the entire branch and build everything locally, on the command line, by just passing the tfsbuild.proj file to msbuild.exe. Also, developers can own the tfsbuild.proj file without having write access to change the build definition.
What is the replacement for the TFSBuild.proj file in TFS 2013?
My requirements are:
Clean build configuration.
Can easily build everything locally.
What is the solution to this problem in TFS 2013?
Create a wrapper MSBuild .proj that your TFS build definition uses. We use this technique for NuGet package restore, but it can equally be used to chain together multiple solution files.
For local builds you can use msbuild with that .proj wrapper as the target (I just build the .sln file directly as there is only 1).
.proj file (not suggesting that you should use this exact .proj file, just an example)
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
</PropertyGroup>
<ItemGroup>
<Solution Include="$(SourceHome)*.sln">
<AdditionalProperties>OutDir=$(OutDir);Configuration=$(Configuration)</AdditionalProperties>
</Solution>
</ItemGroup>
<Target Name="RestorePackages">
<Exec Command=""$(ToolsHome)NuGet\NuGet.exe" restore "%(Solution.Identity)"" />
</Target>
<Target Name="Clean">
<MSBuild Targets="Clean"
Projects="#(Solution)" />
</Target>
<Target Name="Build" DependsOnTargets="RestorePackages">
<MSBuild Targets="Build"
Projects="#(Solution)" />
</Target>
<Target Name="Rebuild" DependsOnTargets="RestorePackages">
<MSBuild Targets="Rebuild"
Projects="#(Solution)" />
</Target>
I've created a .NET project of type Analyzer with Code Fix (.NET Standard) in Visual Studio 2017. The analyzer created by this project type could be deployed as either a NuGet package or a VSIX extension. I used the Generate NuGet Package on Build setting in project properties and it works very smoothly and without any problem.
The thing is, now I want to add some dependencies to the created NuGet package. I know that this is possible through a .nuspec file for other situations. But in this project type, VS creates the NuGet package in bin folders and there is no .nuspec file whatsoever.
So how can I add dependencies to the created NuGet package in the above scenario?
In Visual Studio 2017 using the new .csproj format, the NuGet dependencies are automatically copied into the NuGet package based on the .csproj file's PackageReferences.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.3;net45</TargetFrameworks>
<DefineConstants Condition=" '$(TargetFramework)' == 'netstandard1.3' ">$(DefineConstants);LIBLOG_PORTABLE</DefineConstants>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<!-- /* Package references for .NET Standard 1.3 */ -->
<PackageReference Include="Microsoft.CSharp" Version="4.4.0" />
<PackageReference Include="System.IO.MemoryMappedFiles" Version="4.3.0" />
<PackageReference Include="System.Resources.ResourceManager" Version="4.3.0" />
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.4.0" />
<PackageReference Include="System.Runtime" Version="4.3.0" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
</ItemGroup>
</Project>
So the only thing extra you need to do is add those dependencies from NuGet to your project. This can be done either by
Manually editing the project file (Right-click the project in Solution Explorer and choose Edit <projectName>.csproj)
Installing the NuGet package via NuGet Package Manager
Changing Dependencies by Updating a .nupkg File
Alternatively, since a .nupkg file is just a .zip file with a different extension, you can change its contents:
Unzip it with a standard zip utility to a temporary directory
In the temporary directory, modify the contents of its .nuspec file, adding additional dependencies as appropriate
Zip the contents of the temporary directory again
Rename the new .zip file, giving it the extension .nupkg