Search code examples
teamcity.net-coreoctopus-deploy

Setting version of dotnet core project when using Team City and Octopus Deploy?


I have a dotnet core project that I want to build and deploy.

Currently I have three steps in TC;

  • dotnet restore
  • dotnet pack
  • octopus deploy: push

In OD I wish to use the version which is stamped into the package that OD receives in build-in repository.

It almost works!

However!

TC always builds to a file like Ajf.IdentityServer.1.0.0-54.nupkg (step 2, dotnet pack).

The step 2, dotnet pack, has an option - Version Suffix - where I'm currently using %build.counter%.

I want the version to be formed as 1.0.0.54, not 1.0.0-54.

Apparently, there's no problem in OD (I can deploy those malformed versions), but it just feels... wrong?

How can I stamp my versions with the 'right' version as calculated by TC?

Thanks! ;)


Solution

  • You can introduce an additional property to use in MSBuild.

    If you modify your csproj to set the version like this to introduce a custom BuildNumber property which defaults to 0:

    <PropertyGroup>
      <BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
      <VersionPrefix>1.2.3.$(BuildNumber)</VersionPrefix>
    </PropertyGroup>
    

    Then you can pass BuildNumber as an additional parameter to all relevant dotnet invocations:

    dotnet pack -c Release /p:BuildNumber=%build.counter%