tanathos
tanathos

Reputation: 5606

Azure DevOps .NET Core build and publish doesn't keep given application version

I've an ASP.NET Core application I'm publishing on a dedicated server via Azure DevOps build/release pipelines.

I'm managing the application version number with the GitVersion task (gittools.gitversion.gitversion-task.GitVersion@4) in the YAML build.

The build step is something like:

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: custom
    custom: build
    workingDirectory: src/MyAppProjectFolder
    arguments: '-p:Version=$(GitVersion.FullSemVer)'

And is correctly generating the .exe with the given FullSemVer (I'm inspecting the Azure agent work folder)

Then I've the publish step:

- task: DotNetCoreCLI@2
  displayName: 'dotnet publish'
  inputs:
    command: publish
    publishWebProjects: false
    arguments: '--output $(build.artifactstagingdirectory) --no-restore --no-build'
    workingDirectory: src/MyAppProjectFolder

For some reason the same .exe i found in the C:\agent_work\1\a\a.zip created by the publish DOESN'T have the correct version number, but the generic 1.0.0.

If I "emulate" the pipelines manually on the same server (with dotnet build and dotnet publish manually via powershell, same parameters) everything works as expected.

What's going on? Is there a way to ensure the application to keep the $(GitVersion.FullSemVer) version?

Note: I had to add

- task: UseDotNet@2
  displayName: 'Use .Net Core sdk 2.1.x'
  inputs:
    packageType: sdk
    version: 2.1.x
    installationPath: $(Agent.ToolsDirectory)/dotnet
    includePreviewVersions: true

in front of each NET Core task, as explained here, after the agents have been updated to .NET Core 3.0 (before these builds worked well).

Upvotes: 0

Views: 1066

Answers (1)

Tony
Tony

Reputation: 51

Try adding -p:Version=$(GitVersion.FullSemVer) to your arguments for the publish step.

Upvotes: 1

Related Questions