question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] GitVersion.MsBuild does not set environment variables

See original GitHub issue

Describe 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
arturciccommented, Feb 14, 2021

I think we need to change to make it consistent with the app

1reaction
ThomasPiskolcommented, Feb 14, 2021

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: use IConfigProvider to get GitVersion.Model.Configuration.Config and then get the current value of update-build-number.

What do you think @asbjornu?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found