You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Combo of files that add git metadata to your dlls and nugets
Put Directory.Build.props and Directory.Build.targets to root of your repository (or to where exist .sln file). These files are automatically added by msbuild to all projects (csprojs) that are in file system in folders under .targets and .props files.
On your CI set required GitBranch msbuild property. This is required because most of CI do not checkout to branch, but to commit so you need explicitly add this to msbuild (dotnet cli). It is added to nuget metadata.
[optional] (but recommended) - BuildNumber is used for build number for prerelease packages (it is used . instead of + because nuget do not support it). If is not filled, is used git SHA (with this is not working proper prerelease sorting in git) (i.e. 20201222.12 will be `1.0.0-prereleasefield..20201222.12)
[optional] - PreReleaseField is used for specifying prerelease field. If is not filled it is created from git branch name without "/"
Git metadata in nugets (repository url, git branch, git commit)
Add Directory.Build.props and Directory.Build.targets to root of you project (beside .sln)
Set props in Directory.Build.props
On you CI specify build props like
variables:
projectToNuget: './GitMetadataInfrastructure/GitMetadataInfrastructure.csproj'# this just normalize branch name - i.e. from `refs/heads/master` do just `master`gitBranch: ${{ replace(variables['Build.SourceBranch'],'refs/heads/','') }}buildConfiguration: Releasesteps:
#restore step#build step# by cli this could be # dotnet pack ./GitMetadataInfrastructure/GitMetadataInfrastructure.csproj -c Release -p:BuildNumber=123 -p:GitBranch="mysuperfeature"
- task: DotNetCoreCLI@2displayName: "Pack ${{ parameters.projectToNuget}}"inputs:
command: 'pack'packagesToPack: $(projectToNuget)versioningScheme: 'off'buildProperties: 'BuildNumber=$(Build.BuildNumber);GitBranch=$(gitBranch)'arguments: '--configuration $(buildConfiguration)'
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
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