Created
April 19, 2014 19:54
-
-
Save leniency/11095547 to your computer and use it in GitHub Desktop.
MsBuild proj file to create a Nuget package. Uses msbuildtask library for git stuff. This assumes your git tags are in the form of #.# (ie, 1.2) for versioning.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Package"> | |
<PropertyGroup> | |
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> | |
<Configuration Condition="$(Configuration) == ''">Release</Configuration> | |
<Platform Condition="$(Platform) == ''">AnyCPU</Platform> | |
<BuildDir>bin\$(Configuration)\</BuildDir> | |
<OutputPath>bin\$(Configuration)\</OutputPath> | |
<ProjectName Condition="$(ProjectName) == ''"></ProjectName> | |
<ProjectFile>$(ProjectName).csproj</ProjectFile> | |
<PackageDir>c:\Packages</PackageDir> | |
</PropertyGroup> | |
<PropertyGroup> | |
<MSBuildCommunityTasksPath>$(SolutionDir).build</MSBuildCommunityTasksPath> | |
</PropertyGroup> | |
<!-- | |
Update all the assembly info files with generated version info | |
This requires Git tags and $(BuildNumber). | |
--> | |
<Target Name="UpdateAssemblyInfo"> | |
<Message Text="- Modifying AssemblyInfo files ---------------------------" Importance="high" /> | |
<!-- Fetch the git information. --> | |
<GitVersion LocalPath="$(SolutionDir)"> | |
<Output TaskParameter="CommitHash" PropertyName="CommitHash" /> | |
</GitVersion> | |
<GitDescribe LocalPath="$(SolutionDir)" Arguments="--tags"> | |
<Output TaskParameter="CommitCount" PropertyName="CommitCount" /> | |
<Output TaskParameter="Tag" PropertyName="Tag" /> | |
</GitDescribe> | |
<!-- Fetch all AssemblyInfo files --> | |
<CreateItem Include="$(SolutionDir)**\AssemblyInfo.cs"> | |
<Output TaskParameter="Include" ItemName="AssemblyInfoFiles"/> | |
</CreateItem> | |
<!-- Build the full assebly version. --> | |
<PropertyGroup> | |
<Version>$(Tag).$(CommitCount)</Version> | |
<InformationVersion>$(BuildNumber) ($(CommitHash))</InformationVersion> | |
</PropertyGroup> | |
<!-- Clear any read-only attributes on the files. --> | |
<Attrib Files="@(AssemblyInfoFiles)" Normal="true" /> | |
<!-- Update AssemblyVersion --> | |
<FileUpdate Files="@(AssemblyInfoFiles)" | |
Regex="AssemblyVersion\(".*"\)\]" | |
ReplacementText="AssemblyVersion("$(Version)")]" /> | |
<!-- Update AssemblyInformationalVersion --> | |
<FileUpdate Files="@(AssemblyInfoFiles)" | |
Regex="AssemblyInformationalVersion\(".*"\)\]" | |
ReplacementText="AssemblyInformationalVersion("$(InformationVersion)")]" /> | |
<Message Text="AssemblyInfo files updated to version "$(Version)"" /> | |
<Message Text="AssemblyInformationVersion files updated to version "$(InformationVersion)"" /> | |
<Message Text="----------------------------------------------------------" Importance="high" /> | |
</Target> | |
<Target Name="BuildLibrary" DependsOnTargets="UpdateAssemblyInfo"> | |
<Message Text="-------------------------------------------------------" Importance="high" /> | |
<Message Text="Building $(ProjectFile)." Importance="high" /> | |
<MSBuild Projects="$(SolutionDir)$(ProjectName)\$(ProjectFile)" Targets="Clean;Rebuild" /> | |
</Target> | |
<Target Name="Package" DependsOnTargets="BuildLibrary"> | |
<Message Text="-------------------------------------------------------" Importance="high" /> | |
<Message Text="Packaging $(ProjectFile)." Importance="high" /> | |
<Message Text=" Vars: SolutionDir | $(SolutionDir)" Importance="high" /> | |
<Message Text=" ProjectName | $(ProjectName)" Importance="high" /> | |
<Message Text=" ProjectFile | $(ProjectFile)" Importance="high" /> | |
<Message Text=" PackageDir | $(PackageDir)" Importance="high" /> | |
<Message Text=" MSBuildToolsPath | $(MSBuildToolsPath)" Importance="high" /> | |
<Message Text=" MSBuildCommunityTasksPath | $(MSBuildCommunityTasksPath)" Importance="high" /> | |
<!-- | |
Execute the NuGet pack command. | |
Nuget.exe pack {Project.csproj} | |
-OutputDirectory {Packages} | |
-Verbose | |
-Symbols | |
-Build | |
-Properties Configuration=Release | |
--> | |
<Exec | |
Command=""$(SolutionDir).nuget\NuGet.exe" pack "$(SolutionDir)$(ProjectName)\$(ProjectFile)" -OutputDirectory "$(PackageDir)" -Verbose -Symbols -Build -Properties Configuration=Release"/> | |
</Target> | |
<Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.targets"/> | |
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | |
<Import Project="$(SolutionDir).nuget\nuget.targets" /> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment