独立的.NET Core应用程序

Just in case you missed it, .NET is all open source now and .NET Core is a free, open source, cross-platform framework that you can download and start with in <10 minutes. You can get it on Mac, Windows, and a half-dozen Unixes at http://dot.net. Take that along with the free, cross-platform Visual Studio Code and you'll be writing C# and F# all over the place.

万一您错过了它,.NET现在全部开放源代码,而.NET Core是一个免费的开放源代码跨平台框架,您可以在不到10分钟的时间内下载并开始使用。 您可以在Mac,Windows和六个Unixes上找到它,网址http://dot.net 。 将其与免费的跨平台Visual Studio代码一起使用,您将在各处编写C#和F#。

Ok, that said, there's two ways to deploy a .NET Core application. There's FDD and SCD. Since TLAs (three letter acronyms) are stupid, that's Framework-dependent and Self-contained. When .NET Core is installed it ends up in C:\program files\dotnet on Windows, for example. In the "Shared" folder there's a bunch of .NET stuff that is, well, shared. There may be multiple folders, as you can see in my folder below. You can have many and multiple installs of .NET Core.

好的,那就是说,有两种方法来部署.NET Core应用程序。 有FDD和SCD。 由于TLA(三个字母的首字母缩写)很愚蠢,因此依赖于框架并且是自包含的。 例如,安装.NET Core后,它最终位于Windows上的C:\ program files \ dotnet中。 在“共享”文件夹中,有一堆共享的.NET文件。 如下面的我的文件夹中所示,可能有多个文件夹。 您可以安装许多多个.NET Core。

When you're installing your app and its dependencies BUT NOT .NET Core itself, you're dependent on .NET Core already being on the target machine. That's fine for Web Apps or systems with lots of apps, but what if I want to write an app and give it to you as zip or on a USB key and and I just want it to work. I'll include .NET Core as well so the whole thing is a Self Contained Deployment.

当您安装应用程序及其依赖项但不是.NET Core本身时,您将依赖于目标计算机上已经存在的.NET Core。 对于Web Apps或具有许多应用程序的系统来说,这很好,但是如果我想编写一个应用程序并以zip或USB密钥的形式提供给您,而我只是希望它能正常工作,那该怎么办。 我还将包括.NET Core,因此整个过程都是自包含部署。

It will make my "Hello World" application larger than if I was using an existing system-wide install, but I know it'll Just Work because it'll be totally self-contained.

这将使我的“ Hello World”应用程序比我使用现有的系统范围内的安装程序更大,但我知道它可以正常工作,因为它将完全独立。

Where is .NET Core installed to?

If I deploy my app along with .NET Core it's important to remember that I'll be responsible for servicing .NET Core and keeping it up to date. I also need to decide on my target platforms ahead of time. If I want it to run on Windows, Mac, and Linux AND just work, I'll need to include those target platforms and build deployment packages for them. This all makes mostly intuitive sense but it's good to know.

如果我将应用程序与.NET Core一起部署,请务必记住,我将负责维护.NET Core并保持其最新状态。 我还需要提前确定目标平台。 如果我希望它可以在Windows,Mac和Linux上运行并且可以正常运行,则需要包括这些目标平台并为其构建部署程序包。 所有这些基本上都是直观的,但很高兴知道。

I'll take my little app (I'm just using a "dotnet new" app) and I'll modify project.json in a text editor.

我将使用我的小应用程序(我仅使用“ dotnet new”应用程序),并在文本编辑器中修改project.json。

My app is a .NETCore.App, but it's not going to use the .NET Core platform that's installed. It'll use a local version so I'll remove "type="platform"" from this dependency.

我的应用程序是.NETCore.App,但不会使用已安​​装的.NET Core平台。 它将使用本地版本,因此我将从此依赖项中删除“ type =“ platform”“。

"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1"
}
}
}
}

Next I'll make a runtimes section to specify which ones I want to target. There's a list of ALL the Runtime IDs here.

接下来,我将在运行时部分中指定我要定位的对象。 这里有所有运行时ID的列表。

"runtimes": {
"win10-x64": {},
"osx.10.10-x64": {},
"ubuntu.14.04-x64": {}
}

After running "dotnet restore" you'll want to build for each of these like this:

运行“ dotnet restore”后,您将需要为每个这样的构建:

dotnet build -r win10-x64
dotnet build -r osx.10.10-x64
dotnet build -r ubuntu.14.04-x64

And then publish release versions after you've tested, etc.

经过测试后再发布发行版本,等等。

dotnet publish -c release -r win10-x64
dotnet publish -c release -r osx.10.10-x64
dotnet publish -c release -r ubuntu.14.04-x64

Once this is done, I've got my app self-contained in n folders, ready to deploy to whatever systems I want.

完成此操作后,我的应用程序将包含在n个文件夹中,可以随时部署到所需的任何系统。

Self-contained .NET app built for 3 OSs

You can see in the Win10 folder there's my "MYAPPLICATION.exe" (mine is called scd.exe) that can be run, rather than running things like developers do with "dotnet run."

您可以在Win10文件夹中看到可以运行我的“ MYAPPLICATION.exe”(我的名字叫scd.exe),而不是像“ dotnet run”那样运行开发人员要做的事情。

I run foo.exe, not dotnet.exe now

There's lots of good documentation about how you can tune and define exactly what gets deployed with your self contained application over at the .NET Core Docs. You can do considerable trimming to .NET Core, and there's talk of that becoming more and more automated in the future, possibly down to the method level.

.NET Core Docs上有很多很好的文档,说明如何调整和定义由自包含应用程序部署的内容。 您可以对.NET Core进行大量修整,并且有传言称,将来它会变得越来越自动化,甚至可能降至方法级别。

翻译自: https://www.hanselman.com/blog/selfcontained-net-core-applications

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值