Scott Hanselman

Managing dotnet Core 2.0 and dotnet Core 1.x versioned SDKs on the same machine

May 12, 2017 Comment on this post [6] Posted in DotNetCore
Sponsored By

Tons of great announcements this week at the BUILD conference. I'll slowly blog my take on some of the cooler features, but for now here's a rollup of the major blog posts for developers:

You can download and get started with .NET Core 2.0 Preview 1 right now, on Windows, Linux and macOS:

If you already have .NET Core on your machine, you'll already be able to type "dotnet --version" at the terminal or command line. Go ahead and try it now. Mine says:

C:\Users\scott> dotnet --version
2.0.0-preview1-005977

Remember on Windows you can check out c:\program files\dotnet\sdk and see all the SDK versions you have installed:

Lots of .NET Core versions

Typing dotnet will pick the most recent one...but it's smarter than that. Remember that you can set the current SDK version with a global.json file. Global.json's presence will override from the folder its in, all the way down.

If I make a folder on my desktop and put this global.json in it:

{
"projects": [ "src", "test" ],
"sdk": {
"version": "1.0.3"
}
}

It will force my dotnet runner to use the .NET Core SDK version I asked for. That "projects" line isn't needed for the versioning, but it's nice to be able to select what folders have projects inside.

C:\Users\scott\Desktop\test> dir
Directory of C:\Users\scott\Desktop\test
05/11/2017 09:22 PM <DIR> .
05/11/2017 09:22 PM <DIR> ..
05/11/2017 09:23 PM 45 global.json
1 File(s) 45 bytes
2 Dir(s) 85,222,268,928 bytes free

C:\Users\scott\Desktop\test> dotnet --version
1.0.3

At this point - with a valid global.json - making a new project with dotnet new will make an app with a netcoreapp1.x version. If I move elsewhere and dotnet new I'll get a netcoreapp2.0. In this example, it's the pretense of that global.json that "pins" my SDK version.

Alternatively, I could keep the dotnet.exe 2.0 SDK and install 1.x templates. This would mean I could create whatever I want AND pass in the version.

First I'll add the 1.x templates into my 2.0 SDK. This just needs to happen once.

dotnet new -i Microsoft.DotNet.Common.ProjectTemplates.1.x::1.0.0-*

Now, even though I'm "driving" things with a .NET Core 2.0 SDK, I can pass in --framework to control the project that gets created!

C:\Users\scott\Desktop\test> dotnet new console -o oneone --framework netcoreapp1.1
The template "Console Application" was created successfully.

C:\Users\scott\Desktop\test> dotnet new console -o twooh --framework netcoreapp2.0
The template "Console Application" was created successfully.

I can make libraries that target .NET Standard like this, passing in 2.0 or 1.6, or whatever netstandard I need.

C:\Users\scott\Desktop\lib> dotnet new classlib --framework netstandard2.0
The template "Class library" was created successfully.

There's two options that are not exactly opposites, but they'll give you different levels of control, depending on your needs.

  • You can control your SDK versioning folder by folder with global.json. That means your project's directories are "pinned" and know what SDK they want.
    • When you type dotnet new using a pinned SDK, you'll get the new project results for that pinned SDK. Typing dotnet run will do the right thing.
  • You can pass in --framework for templates that support it and dotnet new will create a template with the right runtime version. Typing dotnet run will do the right thing.

This is .NET Core 2.0 Preview 1, but you should be able to install it side by side with your existing apps and have no issues. If you know these few internal details, you should be able to manage multiple apps with multiple versions without much trouble.


Sponsor: Test your application against full-sized database copies. SQL Clone allows you to create database copies in seconds using MB of storage. Create clones instantly and test your application as you develop.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
May 12, 2017 11:25
It's starting to get dangerous with all these names:
- .NET Framework
- .NET Core
- .NET Standard

From my understanding this is:
- The full framework.
- Modularised framework, not all of full framework is included.
- The standard definition of .NET, versions for other OS can target this.
May 12, 2017 17:58
@Peter. That is pretty much correct. .NET Standard defines specifications to be implemented (think interface). .NET Framework and .NET Core are implementations themselves (think class implementing an interface). Like any interface/class combination, the implementing classes can implement the interface and additionally add additional functionality. .NET Core's benefit is that it has implementations for multiple platforms. .NET Framework's benefit is it's additional functionality (WPF, WebForms, etc). But that extra functionality comes at a cost, Windows OS only.
May 13, 2017 12:29
@Richard.
Yes but its to complicated to understand for the majority.

Ed
May 14, 2017 23:49
More convenient to use imo is the official Docker image https://www.microsoft.com/net/core#dockercmd . Keeping your installations "preview-free" ;)
May 15, 2017 21:19
@Peter

.NET Framework is the traditional flavor of .NET distributed with Windows. Use this for desktop Windows app or with ASP.NET 4.5/4.6.

.NET Core is cross-platform .NET that can run on Windows, Mac, and Linux. Use applications that can run on any platform, including Docker.

.NET Core and .NET Framework implements .NET Standards.
May 24, 2017 14:34
Hi Scott,
I have been using git push azure to deploy to my teams code and this has been working until a couple of weeks back when v2 was announced, I have added a global.json to the root of the project specifying sdk 1.0.2 but it does not seem to have an effect, I have the following error:

remote: Generating deployment script.
remote: Running deployment command...
remote: Handling ASP.NET Core Web Application deployment.
remote: ......................
remote: Restoring packages for D:\home\site\repository\UAV\src\UAV.Tests\UAV.Tests.csproj...
remote: ....
remote: D:\Program Files (x86)\dotnet\sdk\2.0.0-preview1-005977\NuGet.targets(97,5): error : Unable to resolve 'D:\home\site\repository\UAV\src\UAV\UAV.csproj' for '.NETF
ramework,Version=v4.6.1'. [D:\home\site\repository\UAV\UAV.sln]
remote: Lock file has not changed. Skipping lock file write. Path: D:\home\site\repository\UAV\src\UAV.Tests\obj\project.assets.json
remote: Restore failed in 8.91 sec for D:\home\site\repository\UAV\src\UAV.Tests\UAV.Tests.csproj.
remote: Restoring packages for D:\home\site\repository\UAV\src\UAV.UITests\UAV.UITests.csproj...
remote: Lock file has not changed. Skipping lock file write. Path: D:\home\site\repository\UAV\src\UAV.UITests\obj\project.assets.json
remote: Restore completed in 326.71 ms for D:\home\site\repository\UAV\src\UAV.UITests\UAV.UITests.csproj.
remote: Restoring packages for D:\home\site\repository\UAV\src\UAV\UAV.csproj...
remote: ........

Any help would be greatly appreciated as I am currently having to manually publish from within VS2017

Thanks

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.