In the latest post I talked about how we can migrate project files from VS 2015 to VS 2017 and the changes introduced in this migration.
One of the improvements is that the new project file is based on .NET SDK that we can use to manage the project.
Of course we can continue to build the project with msbuild, but .NET SDK give us a new option; besides in the future will be the only way to build projects.
Anyway, the project file migration will be reflected in our continuous integration process, if we have one; indeed, the AssemblyInfo file is missing in the new file format, replaced by new settings in csproj file.
I have Atlassian Bamboo as CI server and in order to make it working with the new format of the csproj file, slightly changes has been needed.
However, before to go ahead with the configuration there is a precondition: .NET SDK need to be installed in our CI server; you can download the installation from here.
In the new project file we have some settings that can be used to generate the nuget package:
<TargetFrameworks>net35;net45</TargetFrameworks> <PackageId>MyProject</PackageId> <Authors>My Company</Authors> <Description></Description> <Copyright>Copyright © 2018</Copyright> <AssemblyVersion>184.108.40.206</AssemblyVersion> <FileVersion>220.127.116.11</FileVersion> <Company>My Company</Company>
My requirement is assign a version to the project in the deployment plan of Bamboo; in order to do that, I need to change the AssemblyInfo and FileVersion tags like this:
I’ve parametrized these two tags and I can setup those with the .NET SDK command:
dotnet build /p:VersionNumber=18.104.22.168 /p:Configuration=Release
If we check the dll version in the bin/release folder, we’ll have the one specified above.
One of the most useful features of bamboo are the variables.
There are predefined enviroment variables that we can use like the build number, or we can define our variables at plan level and we’ll be able to use it later in the tasks commands; in our case we need to define a variable about the version number of the project:
I’ve defined a variable that has a fixed part of the version and a dynamic part tied to the bamboo enviroment variable buildNumber; now I can use the variable in my plan:
I’ve used the variable in the .NET SDK command for building the project, the command will replace the version number in the csproj file and the dlls will be versioned correcly.
How we have seen, the use of the vs2017 project format with bamboo variables is a huge improvement of the versioning ad deployment process of visual studio projects and with few steps we are able to manage and dynamically setup variables like the version number.