March 7, Microsoft released Visual Studio RTM, together with the. NET core Runtime 1.1.0 and the. NET Core SDK 1.0.0, although these are not the latest versions, they have been upgraded from the preview version to the official version. Therefore, when you install visual Studio 2017, if you enable the related features of. NET core development, after the installation is complete, you can execute dotnet.exe directly at the command line, where you can see the. net The core version is 1.1.0, and if you execute the dotnet.exe--version command, the SDK version you see will be 1.0.0 (not with the preview word).
Here's how to look at the. NET Core SDK version, mainly from a very interesting thing, and it has a certain impact on. NET core projects migrating from old Xproj+project.json to csproj. If you've ever developed a project using Visual Studio +. NET core Tools for Visual Studio +. NET Core SDK and want to continue developing in the new Visual Studio 2017, learn about this The content of the polygon is still necessary.
Overall, migrating a. NET core project is roughly the following steps:
- Migration readiness
- A single upgrade of a project using visual Studio 2017
- Install the latest version of the. NET Core SDK on the Jenkins CI server
- Modify the Jenkins CI System compilation task to successfully complete the compilation and release
Let me take a look at one of my own open source projects, HAL, for an example of how each step is done.
Migration readiness
The HAL Project was originally an open source project hosted on GitHub, in order to be able to smoothly implement the project migration and ensure that Jenkins CI works properly, I first created a new branch (branch) on GitHub before the project was migrated. The cost of creating a branch in GitHub is very low, and after all the debugging is done, the branch is merged (merge) into the main branch and deleted directly.
After the branch creation in GitHub is complete, update the local code base to complete the code synchronization.
Open and upgrade the. NET core project in Visual Studio 2017
Before I had an article Jianwen, how can you continue to open and compile the Xproj project in Visual Studio 2015 after you have installed Visual Studio RC, because when you finish installing Visual Studio 2017, Dotnet.exe has been upgraded to the 1.0.0 version, and Dotnet.exe is already using MSBuild for Project compilation, and it does not recognize the project type and document organization structure of Xproj+project.json, so in visual Studio Even if the Xproj project file can be opened in 2015, it will not compile properly. The solution at the time was to create a Global.json file at the root level of the project, explicitly specifying the version of the. NET Core SDK in the file, so that when the project was compiled, the old version of the. NET Core SDK was forced, and the problem was resolved. For more information on how to modify Global.json to specify the SDK version, please refer to this article.
For this problem, we can do an experiment, assuming that your machine is equipped with Visual Studio +. NET core Tools for Visual Studio + preview version of the. NET core SDK, with the visual Studio 2017. Then, when you execute the dotnet.exe--version command directly at the command line, you will see that the. NET Core SDK version is 1.0.0:
If you go to the root of a project that has the SDK version specified in Global.json, and you also execute the dotnet.exe--version command, you will find that the SDK version at this time is the version specified in Global.json:
OK, if you have previously modified the Global.json file so that the Xproj project can continue to open and compile in Visual Studio 2015, you now need to remove the explicit declaration of the SDK version in the Global.json file, otherwise, in the visual Project migration in Studio 2017 will not complete properly. Because Visual Studio uses an older version of the SDK at this point, this version of the SDK does not have migrate functionality.
In general, migrating xproj in Visual Studio 2017 is relatively smooth and stable, and generally does not encounter outlandish problems, only the one-way migration is OK. After the migration is complete, a new solution file (SLN) is generated.
Install the new. NET Core SDK on the Jenkins server
When visual Studio 2017 successfully completed the project migration, you can submit the code to a temporary branch on GitHub so that you can build tests on Jenkins. Prior to this, a new version of the. NET Core SDK needs to be installed. The installation process is simple, and you can download and install it by selecting the appropriate. NET Core SDK on the Dotnet official website based on Jenkins Master or slave's operating system. After the installation is complete, you can use the dotnet--version command to confirm that the. NET Core SDK is installed correctly.
Modifying the Jenkins System compilation task
As far as the HAL project is concerned, I first cloned the build job in Jenkins and then modified the compilation task so that it could get the code from the temporary branch in GitHub. There is no problem with the whole process, the original dotnet Restore/build/pack and other commands will continue to work normally, but you will find that the build process is already using Microsoft Build Engine (MSBuild).
It should be noted that the original dotnet test based on Xunit has a-xml hidden parameter that produces a report of the unit test results in JUnit XML format, but under. NET Core SDK 1.0, this parameter is not available. One solution is to use the-L (--logger) parameter, which produces a unit test report in MSTest format, where a mstest plug-in is installed in Jenkins to continue to display the test report on the home page.
Finally, in GitHub, merge the staging branch into the mainline branch and manually modify the build job for the mainline branch in Jenkins, and finally delete the cloned build job. It is not recommended to continue with the cloned build job, which can cause confusion in the compilation version.
Introduction to the migration of. NET core projects from Xproj+project.json to csproj