在同一台计算机上管理dotnet Core 2.0和dotnet Core 1.x版本的SDK

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:

本周在BUILD会议上发布了许多重要公告。 我将慢慢介绍一些更酷的功能,但是现在这是针对开发人员的主要博客文章汇总:

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

您现在可以在Windows,Linux和macOS上下载并开始使用.NET Core 2.0 Preview 1:

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:

如果您的计算机上已经装有.NET Core,则已经可以在终端或命令行中键入“ dotnet --version”。 继续尝试吧。 我的说:

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:

请记住,在Windows上,您可以检出c:\ program files \ dotnet \ sdk并查看已安装的所有SDK版本:

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.

键入dotnet会选择最近的一个...但是比这更聪明。 请记住,您可以使用global.json文件设置当前的SDK版本。 Global.json的存在将从其文件夹中一直覆盖下去。

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

如果我在桌面上创建一个文件夹并将此global.json放在其中:

{
"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.

这将迫使我的dotnet运行程序使用我要求的.NET Core SDK版本。 版本控制不需要“项目”行,但是很高兴能够选择在其中包含项目的文件夹。

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.

在这一点上-使用有效的global.json-使用dotnet new创建一个新项目将使一个应用程序具有netcoreapp1.x版本。 如果我搬到其他地方并新建dotnet,我将得到一个netcoreapp2.0。 在此示例中,正是global.json的伪装“固定”了我的SDK版本。

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.

另外,我可以保留dotnet.exe 2.0 SDK并安装1.x模板。 这意味着我可以创建我想要的任何东西,并在版本中传递。

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

首先,我将1.x模板添加到我的2.0 SDK中。 这只需要发生一次。

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!

现在,即使我使用.NET Core 2.0 SDK进行“驱动”,我也可以传入--framework来控制要创建的项目!

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.

我可以像这样以.NET Standard为目标的库,传入2.0或1.6,或者我需要的任何netstandard。

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.

    您可以使用global.json逐个文件夹控制SDK版本控制文件夹。 这意味着您的项目目录是“固定”的,并且知道他们想要什么SDK

    • 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.

      使用固定的SDK键入dotnet new时,将获得该固定的SDK的新项目结果。 键入dotnet run将做正确的事。
  • 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.

    您可以为支持它的模板传入--framework, dotnet new将使用正确的运行时版本创建模板。 键入dotnet run将做正确的事。

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.

这是.NET Core 2.0 Preview 1,但您应该能够将其与现有应用程序并排安装,并且没有问题。 如果您了解这些内部细节,则应该可以轻松管理具有多个版本的多个应用程序。

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.

赞助者针对完整数据库副本测试您的应用程序。 SQL Clone允许您使用MB的存储空间在几秒钟内创建数据库副本。 立即创建克隆并在开发时测试您的应用程序。

翻译自: https://www.hanselman.com/blog/managing-dotnet-core-20-and-dotnet-core-1x-versioned-sdks-on-the-same-machine

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值