This post is from the series about upgrading our project to ASP.NET Core 2.0. Now, we have upgraded Visual Studio 2017 version 15.3 locally. We updated the source code to target ASP.NET Core 2.0. However, automated build in TFS 2017 fails of course. Let’s talk about how we upgraded our builds.
Upgrading of build agent
First step (and I assumed the only one) was to install Visual Studio 15.3 and .NET Core 2.0 SDK into the build agent. This was a simple manual step. Currently, we don’t have exhaustive number of build agents and each build agent is pretty unique, so manual management of build agents is sufficient for our needs.
After installation I started build agent service and tried to queue the build from asp-netcore20 branch. I was very surprised, when it said that there is no build agent able to build. I checked the agent pool and the agent was running. However, I noticed it lacked VisualStudio_15.0 capability. This capability is specified in the continuous integration build definition, so that it is queued only to build agent with Visual Studio 2017. So it seemed that the build agent hadn’t identified the installation of Visual Studio 2017 correctly. The version of the installed build agent was 2.112.
I guess that the elegant solution would be upgrading TFS 2017 Update 2. This would auto-update build agents and build tasks and none of the work mentioned below would be necessary. However, upgrading of TFS instance is much more work, it involves more roles and affects other teams. Although it is planned, just not executable yet.
Tip: If you want to install the newest version of TFS/VSTS build agent, do not follow link at agents pool page in TFS. Rather open GitHub page with releases of build agents. https://github.com/Microsoft/vsts-agent/releases
So I downloaded build agent version 2.120.1 from GitHub page. I uninstalled the old agent and installed the new one. This version identified installation of Visual Studio 2017 correctly and the list of capabilities was correct again.
Upgrading of NuGet restore
Unfortunately upgrading of build agent does not upgrade build tasks as these are downloaded from TFS, so I expected some more work to do. Anyway, I queued a new build. Restoring of NuGet packages failed. And that was the first step actually. There were lot of error messages like “Project XY is not compatible with netcoreapp2.0”. There was NuGet version 4.0.0 installed at the server. And it seems this version does not support .NET Core 2.0 targets. So I downloaded version 4.3.0 from https://www.nuget.org/downloads. I copied it into Program Files directory at the server. And I created a new environment variable named NuGet. Then I specified this variable as path to NuGet in Restore NuGet task. The path was specified as $(NuGet).
Upgrading of Visual Studio Build
I queued a new build again. And it succeeded. Actually I was surprised, because I expected it to fail. But there were some warnings that each project in the solution was skipped, because it was not supported by current version of MS Build. I looked into logs and build used version 4.0 of msbuild.exe. However, Visual Studio 2017 uses version 15.0 of msbuild.exe. As I suspected Visual Studio Build task in the build definition hadn’t identified the installation of Visual Studio 2017 correctly.
At first I created a new environment variable at server running the build agent. The variable was named TFS_MSBuild and the value was correct path to MSBuild.exe. By default is is C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\msbuild.exe.
Next step was to update the build definition. I removed Visual Studio Build task and added MSBuild task instead. I setup same path to solution file, same platform and same configuration. Then I specified to use specific location of MSBuild and in Path I entered $(TFS_MSBuild). Then in MSBuild arguments field I entered /p:VisualStudioVersion=“15.0”.
Upgrading of Visual Studio Test
Of course the same problem was with VSTest. Well, I used the similar solution. I created environment variable $(TFS_VSTest). The default installation path is C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe. And then simply specified this variable in Visual Studio Test task. Again in format $(TFS_VSTest).
However, after running the build, there were no test results. We changed the target of test libraries from net47 to netcoreapp2.0 and it seems that running of VS Test in TFS build does not discover tests in these kind of libraries. At that moment, it was not critical to target netcoreapp2.0 with our tests. We didn’t plan to go multi-platform. So we changed target back to net47 and testing in build worked again.
End of path
This is the end of our path of upgrading a project to ASP.NET Core 2.0.