Thursday, 1 August 2019

Build .NET Core 3.0 Projects with Azure DevOps Pipeline Using Hosted Agents

.NET Core 3.0 is still in preview 7 and some of you may have already started developing projects with it. Implementing CI/CD is important to any project regardless of whether you are using bleeding edge technology or not. It is possible to setup your own build server with the required preview components setup a builds. However, if you can utile the hosted agents in Azure DevOps Services that would remove the burden of maintaining your own build server. Hence, let’s look at the steps required to build a .NET core 3.0 application with hosted 2019 agents.
1. The first step required is setting up a global.json file with below content in the same folder where the Visual Studio solution file is located in your repo. It will allow the MSBuild to use the preview .NET core versions in the build step.
  "sdk": {
    "version": "3.0.100-preview"
2. If you want to dynamically create this file in the build pipeline (to prevent the temporary needed file to be added to the repo),  you can use a PowerShell task with a inline script in your build such as below.
$globaljson = '{"sdk": {"version": "3.0.100-preview"}}';
$globaljson | out-file $(globaljsonPath) -Encoding UTF8

3. Then you need to add Use .NET Core step to the build and you can define which version of the .NET Core preview should be downloaded to the build server. The version number specifications can be found in here.
Then you can use Visual Studio build step to build your solution which is containing a .NET Core 3.0 application.
The usage of dotnet build task is possible as well and you would be able to skip the step 1 and 2 of adding a global.json if you are using dotnet build task. But if you want to build the entire solution with Visual Studio build step you have to follow the steps described above.

No comments:

Popular Posts