So far in this series, we have taken a look at the .NET Core Tools 1.0.0-preview2 (Visual Studio 2015) and the .NET Core Tools 1.0.0-preview4 (Visual Studio 2017). With both versions, we created a project with the command line tools and with Visual Studio. From there we spend some time analyzing each of the files and compared and contrasted the project structure.
In this post, we will take a look at migrating from preview2 to preview4 and discuss any nuances that come with it. This is the final post in a three part series. If you missed any of the previous posts, please feel free to take a look.
There are two options to upgrade your project, with Visual Studio or via the Command Line. For consistency, we will upgrade our command line project with the command line and the Visual Studio project with Visual Studio. Lets start with the command line.
If we run
dotnet --help, we will see that there is a
... migrate Migrates a project.json based project to a msbuild based project ...
Lets run it as see what happens!
> dotnet migrate Project JrTech.Core101.Cmd migration succeeded (C:\Users\Jason\Desktop\JrTech.Core101.Cmd) Summary Total Projects: 1 Succeeded Projects: 1 Failed Projects: 0
This leaves us with the following file structure.
├── backup | └── project.json | └── project.lock.json ├── bin ├── obj ├── JrTech.Core101.Cmd.csproj ├── Program.cs
The backup folder contains copys of the original project.json and project.lock.json files. This is nice in case we have to revert our changes but, of course we have everything in source control :). Lets take a look at the csproj file.
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> <PropertyGroup> <TargetFramework>netcoreapp1.0</TargetFramework> <DebugType>portable</DebugType> <AssemblyName>JrTech.Core101.Cmd</AssemblyName> <OutputType>Exe</OutputType> <PackageTargetFallback Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback> </PropertyGroup> <ItemGroup> <Compile Include="**\*.cs" /> </ItemGroup> <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' "> <PackageReference Include="Microsoft.NETCore.App"> <Version>1.0.1</Version> </PackageReference> </ItemGroup> <PropertyGroup Condition=" '$(Configuration)' == 'Release' "> <DefineConstants>$(DefineConstants);RELEASE</DefineConstants> </PropertyGroup> </Project>
Very similar as if we would have created the project from scratch. While there are a few additional elements added to the xml, there doesn’t appear to be anything of significance. Lets try running the project to make sure everything went through fine.
> dotnet run Hello World!
Well that was pretty straight forward. Everything looks good. Lets try out the upgrade process with Visual Studio.
With Visual Studio 2017 RC open, we browse to the solution we created with Visual Studio 2015. Upon doing so, we get the typical Visual Studio upgrade dialog.
After the upgrade is completed, we are presented with a Migration Report. If you’re familiar with Visual Studio, chances are you’ve see this report in the past.
Next lets run the solution and make sure everything will build without errors. Everything works fine and we get the same output.
Now lets have a look at the project structure.
├── backup | └── JrTech.Core101.Vs.sln | └── src | | └── JrTech.Core101.Vs | | | └── JrTech.Core101.Cmd.xproj | | | └── project.json ├── src | | └── JrTech.Core101.Vs | | | └── bin | | | └── obj | | | └── Properties | | | └── JrTech.Core101.csproj | | | └── JrTech.Core101.xproj | | | └── Program.cs | | | └── project.json | | | └── project.lock.json ├── global.json ├── JrTech.Core101.Cmd.sln ├── UpgradeLog.htm
Similar situation as before. All the old files are placed in a
backup directory. Unfortunately, the old project files (xproj, project.json, etc) are left in the main project folder. Of course, less than desirable. I ran the upgrade several times and wound up with the same results.
In fairness, this is an RC version of the software but, rest assured, I will be reporting this with the team so they can fix it by the time Visual Studio if officially released.