Skip to content

Instantly share code, notes, and snippets.

@radleta
Created June 27, 2011 21:41
Show Gist options
  • Save radleta/1049910 to your computer and use it in GitHub Desktop.
Save radleta/1049910 to your computer and use it in GitHub Desktop.
NuGet Package and Publish Example for MSBUILD
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!-- snip -->
<PackageDir>Package\$(Configuration)</PackageDir>
</PropertyGroup>
<!-- snip -->
<Target Name="AfterBuild">
<!-- Load up the information from the assembly -->
<GetAssemblyIdentity AssemblyFiles="$(OutputPath)$(AssemblyName).dll">
<Output TaskParameter="Assemblies" ItemName="OutputAssemblyInfo" />
</GetAssemblyIdentity>
<Message Text="Info: %(OutputAssemblyInfo.Version)" />
</Target>
<Target Name="Package">
<!-- Ensure the Package directory exists for this project -->
<RemoveDir Directories="$(PackageDir)" />
<MakeDir Directories="$(PackageDir)" />
<!-- Package the project -->
<Exec WorkingDirectory="$(BuildDir)" Command="NuGet.exe pack -Symbols -OutputDir &quot;$(PackageDir)&quot; -Version %(OutputAssemblyInfo.Version)" />
</Target>
<Target Name="Publish">
<!-- Publish the nupkg to the well known NuGet server
Note: "nuget setApiKey {put-your-api-key-here} -Source http://My_Nuget_Gallery_Service_Url/" must be run prior on the machine to ensure the api key is set correctly. -->
<Exec WorkingDirectory="$(PackageDir)" Command="NuGet.exe push &quot;$(AssemblyName).%(OutputAssemblyInfo.Version).nupkg&quot; -Source http://My_Nuget_Gallery_Service_Url/" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment