static void

Updating a class library to dotnet Core RC2

net Core RC2 came out on 2 days ago (May 16 2016). I tried upgrading a simple class library so that it can support .net Core RC2 plus older .net frameworks.

It was relatively straightforward, unlike RC1. Here's what I did.

The library I used was very simple (my public holidays project). There is just one project. We're not doing tests for now- we're using vanilla MsTest. RC2 still only supports XUnit, but we should get MsTest for RTM. For now, we want to be able to use the "classic" solution, with tests, and add a parallel "Core" solution that sits alongside it.

Installing RC2

If upgrading from RC1, clear the nuget cache: nuget locals all -clear

If you upgrade projects, there are numerous low-level changes (project.json structure, package names)

If you installed older versions of RC2/dotnet CLI, uninstall them via Programs + Features ("Microsoft Dotnet CLI for Windows". You can also get rid of "Microsoft ASP.Net 5 RC1 Update 1" which seemed to work but didn't disappear from the list)

If you forget (as I did!), VS shows the error "The project is configured to use .NET Core SDK version 1.0.0-preview1-002702 which is not installed or cannot be found."

We're just using the standard library (we could depend on loads of individually specified packages, but this is very concise).

The package/dll name is the folder name.

Not sure why we're importing dnxcore50, when dnx is supposed to be gone- from the discussion on github it looks like another transitional thing. Maybe it will be gone for RTM in June.

You can use framework netstandard1.5 or roll back to netstandard1.0. For 1.0 - 1.2, it red-lined on [assembly: Guid( attribute in AssemblyInfo.cs. So netstandard1.3 it is.

I opened up the old solution. Building in Visual Studio broke: "Your project is not referencing the ".NETFramework,Version=v4.0" framework. Add a reference to ".NETFramework,Version=v4.0" in the "frameworks" section of your project.json, and then re-run NuGet restore."

The workaround (from the github issue) is to add <ResolveNuGetPackages>false</ResolveNuGetPackages> to the .csproj. If you have packages, tough.

We now have a dll and pdb in bin/Debug/netstandard1.3
We also have a json file, (x.deps.json), which shows you everything in .NETStandard,Version=v1.3

Parallel solutions

I created a second solution alongside the current solution (essentially the same, minus the test project).

Next, alongside the current project, I added an xproj file (a cut-down csproj). To get this file, I created a new Core library in Visual Studio in a different folder, and stole the xproj. I had to change the <RootNamespace>x</RootNamespace>.

I also changed the <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> ( to .\bin\core\ ) so building the current and new projects put things in different places. Note this only works in Visual Studio- "dotnet build" doesn't look at the .xproj. Instead you have to >dotnet build -c Release -o .\bin\core\ -f netstandard1.3 (note you have to specify the framework when you use --output).

Multi-targeting

Adding older frameworks to project.json is as simple as adding the targets (which are the same as used in nuget).