[Bug] GitVersion.MsBuild does not set environment variables
See original GitHub issueDescribe the bug
GitVersion.MsBuild
(5.6.6) does not create environment variables containing the version information calculated by GitVersion.
Maybe this is related to #2552
Expected Behavior
The following environment variables were present after building a .NET Standard 2.0 library project with dotnet build
using GitVersionTask
(5.5.1):
GitVersion_AssemblySemFileVer
GitVersion_AssemblySemVer
GitVersion_BranchName
GitVersion_CommitDate
GitVersion_CommitsSinceVersionSource
GitVersion_CommitsSinceVersionSourcePadded
GitVersion_EscapedBranchName
GitVersion_FullBuildMetaData
GitVersion_FullSemVer
GitVersion_InformationalVersion
GitVersion_LegacySemVer
GitVersion_LegacySemVerPadded
GitVersion_Major
GitVersion_MajorMinorPatch
GitVersion_Minor
GitVersion_NuGetVersion
GitVersion_NuGetVersionV2
GitVersion_Patch
GitVersion_PreReleaseTag
GitVersion_SemVer
GitVersion_Sha
GitVersion_ShortSha
GitVersion_UncommittedChanges
GitVersion_VersionSourceSha
GitVersion_WeightedPreReleaseNumber
Actual Behavior
No GitVersion_
environment variables are present when GitVersion.MsBuild
(5.6.6) is used.
Steps to Reproduce
- create a .NET Standard 2.0 Library project and add
GitVersion.MsBuild
:
dotnet new classlib -f netstandard2.0
dotnet add package GitVersion.MsBuild --version 5.6.6
- setup GitHub Actions pipeline to build the project using
dotnet build
- add a pipeline step to print all environment variables, e.g. via PowerShell:
Get-ChildItem env:* | Sort-Object Name | Format-Table -AutoSize | Out-String -Width 900
Context
The environment variables should be set also by GitVersion.MsBuild
. It’s quite common in a CI pipeline to use the calculated version for some other tasks.
In this case a GitHub release should be created using the SemVer as the name of the release and as the value for tag.
Your Environment
- GitHub Actions CI
- dotnet SDK 3.1.406
- Version Used:
GitVersion.MsBuild
(5.6.6) - Operating System and version (Windows 10, Ubuntu 18.04): Ubuntu (18.04.5 LTS).
- Link to your project
- Link to your CI build (if appropriate):
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:8 (8 by maintainers)
Top Results From Across the Web
[Bug] GitVersion.MsBuild does not set Azure DevOps build ...
Hello, I have a C# project that uses the GitVersionTask package. The project is built in an Azure DevOps pipeline. When running the...
Read more >c# - What does the environment variable ...
According to the maintainers of GitVersion, this variable just suppresses a BugException that otherwise gets throw in this situation.
Read more >MSBuild Task
MsBuild — is a simple solution if you want to version your assemblies ... out how the version variables are set and how...
Read more >Azure DevOps
To use GitVersion's variables in the build name, just add them in the form $(GITVERSION_FullSemVer) into the Build definition's build number string. Then...
Read more >Version Variables
Version variables are quite useful if you need different formats of the version number. Running the gitversion executable in your repository will show...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think we need to change to make it consistent with the app
Yes, I’m able to reproduce it in a test case and I have a fix for the GitHubActions issue. Probably I’m able to create a pull request next week.
But I’m not sure how to properly fix the hard coded value in
GitVersionTaskExecutor
.My current idea is to make it similar like
GitVersionExecutor
in GitVersion.App: useIConfigProvider
to getGitVersion.Model.Configuration.Config
and then get the current value ofupdate-build-number
.What do you think @asbjornu?