I was keen to get TestCop creating the nuget package for me automatically during the release build. The following outlines the change made to support this.

Identify where you are going to store the following files (I use a folder called InstallSupport) - obviously these should be under source control with your solution.
  • NuGet.exe
  • youproject.nuspec (see below)
  • nuget.build.bat (see below)

Update csproj

Add an 'AfterBuild' step to your project's csproj file to call a utility batch file that will do the actual packaging. The batch file is called with the assembly version for the project and the output folder of the project as this information is easy to retrieve within msbuild. I've added a condition so we only package during a Release build.

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    <Message Text="Releasing %(AssemblyVersion.Version)" Importance="high" />
    <Exec Command="$(ProjectDir)\..\InstallSupport\nuget.build.bat %(AssemblyVersion.Version)" WorkingDirectory="$(OutputPath)" />

It is worth at this point creating a mock nuget.build.bat to check that your project still compiles. Put a single line in it

 @ECHO %1 %2

to confirm that all is working. You will see the output when you do a Release build.

Create a NUSPEC file

Create a nuspec file for your project. This file defines how nuget will package up your application. Note that the batch file will override the 'version' number with the assembly version when it calls NuGet to build the package.

Create the nuget.build.bat

Next copy and text below into your nuget.build.bat file. Change the path to Nuget and update project references and publish folder to match your own.
SET NUGET=..\..\..\..\InstallSupport\NuGet.exe

@ECHO ===NUGET Publishing Version %VER% to %OUTDIR%
%NUGET% pack -Symbols -Version %VER% TestCop.nuspec
%NUGET% push Resharper.TestCop.%VER%.symbols.nupkg -ApiKey XXX -Source %OUTDIR%


Last edited Dec 19, 2013 at 2:19 PM by SomethingUseful, version 9