Azure Pipelines - use tool downloaded from NuGet in .NET Core project

Viewed 445

How do I configure build step in Azure Pipelines to execute command GitVersion.exe if the executable is obtained from NuGet GitVersion.CommandLine by .NET Core project?

In .NET Framework executable could be found in path packages/GitVersion.CommandLine/**/GitVersion.exe, but in .NET Core packages directory doesn't exist.

2 Answers

You can install the Git Version extension and add it to your pipeline, it works also with .NET Core projects.

The extension generates 2 variables:

GitVersion.NuGetVersion
GitVersion.SemVer

You can use those variables in the next steps: $(GitVersion.SemVer).

For example (in yaml):

steps:

- task: GitVersion@4
  displayName: GitVersion

- powershell: 'Write-Host $(GitVersion.SemVer)'

Result:

enter image description here

If you want to use specific version, you can add a command line task and install it with chocolaty:

choco install gitversion.portable

By the way, Microsoft Hosted VS2017/2019 Agents include GitVersion 4.0.0 installed.

.NET Core 2 introduced the concept of Nuget caching (a bit similar to GAC). All packages downloaded only once to a specific folder and reused for all projects. It is needed because of .NET Core 2.x-3.x now composed from hundreds of packages. So the framework now is very granular you use what you need or an "aggregating" package e.g. microsoft.aspnetcore.all (which references everything).

So now you can find installed Nuget packages under you User account e.g.: C:\Users\< your userName >.nuget\packages.

According to this documentation you can run this command which will list all Nuget folders on your machine:

dotnet nuget locals all -l

If you cannot access this folder or you don't know the User name on your build agent, I would suggest to download that tool and check it into your Git repo so you have a fixed path.

Related