Scott Hanselman

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

May 12, '17 Comments [10] 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

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

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
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Friday, 12 May 2017 07:25:31 UTC
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.
Friday, 12 May 2017 13:58:37 UTC
@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.
Saturday, 13 May 2017 08:29:02 UTC
Yes but its to complicated to understand for the majority.

Sunday, 14 May 2017 19:49:51 UTC
More convenient to use imo is the official Docker image . Keeping your installations "preview-free" ;)
Monday, 15 May 2017 17:19:07 UTC

.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.
Tuesday, 16 May 2017 11:16:27 UTC
According to what I know the . .NET Standard should be defining the specifications to the implemented .NET Framework where as the .NET Core are implementations for themselves. Correct me if I am wrong.
Tuesday, 16 May 2017 17:29:49 UTC
yayks this is hard. I was having same troubles with my site which is about flashlight.
Wednesday, 24 May 2017 00:36:04 UTC
I read this article and this is amazing bro
Wednesday, 24 May 2017 10:34:29 UTC
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

Daniel Thomas
Thursday, 25 May 2017 12:38:06 UTC
Lovely article
E-mail (will show your gravatar icon)
Home page
Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, li, ol, pre, strike, strong, sub, super, u, ul) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Live Comment Preview

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