Skip to content

Instantly share code, notes, and snippets.

@PadreSVK
Last active December 14, 2020 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PadreSVK/b59419c76a04e4f30275df1518d0abda to your computer and use it in GitHub Desktop.
Save PadreSVK/b59419c76a04e4f30275df1518d0abda to your computer and use it in GitHub Desktop.
Sample of solution wide additing git metadata to dlls and additing nuget version suffix for non master branch
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<StableVersionBranch>master</StableVersionBranch>
<!-- this should be defined in every csproj - if is not filled dont have affect on functioniality (nuget metadata) -->
<!-- <RepositoryUrl>https://github.com/XXXXX.git</RepositoryUrl>-->
</PropertyGroup>
<ItemGroup>
<PackageReference Include="GitInfo" Version="2.1.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>
<!-- https://github.com/kzu/GitInfo/blob/main/src/GitInfo/build/GitInfo.targets#L544 -->
<Target Name="DecorateVersionsWithGitSha" AfterTargets="GitVersion">
<PropertyGroup>
<!--https://docs.microsoft.com/en-us/dotnet/core/tools/csproj-->
<RepositoryCommit>$(GitSha)</RepositoryCommit>
<RepositoryBranch>$(GitBranch)</RepositoryBranch>
<InformationalVersion>$(GitBranch)-sha.$(GitSha)</InformationalVersion>
</PropertyGroup>
<!-- for pre release versions of nugets -->
<PropertyGroup Condition="'$(GitBranch)' != '$(StableVersionBranch)'">
<!-- Add BuildNumber suffix or GitCommit is BuildNumber is empty -->
<Version Condition="$(BuildNumber) == ''" >$(Version)-pre$(GitCommit)</Version>
<Version Condition="$(BuildNumber) != ''" >$(Version)-pre$(BuildNumber)</Version>
<PackageVersion>$(Version)</PackageVersion>
</PropertyGroup>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment