.NET CLI 如何在 Linux 上发布后运行应用程序 [英] .NET CLI how to run app after publish on Linux
问题描述
我花了大约 4 个小时的调查,仍然无法找到如何运行已发布的应用程序 (dotnet publish
)
I spent ~4 hours investigation and still can't find out how to run published application ( dotnet publish
)
现在我可以将源下载到我的远程机器,然后调用 dotnet build
和 dotnet run
- 然后我的应用程序按预期运行.但我只想将 DLL(或 *.so ?)发布到我的 VPS,而无需源文件.
Now I can download sources to my remote machine, then call dotnet build
and dotnet run
- then my app runs as intended. But I want to publish just DLL's (or *.so ?) to my VPS without source files.
官方文档怎么说?在project.json中定义命令
What official docs says? To define command in project.json
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel --server.urls http://unix:/var/aspnet/HelloMVC/kestrel.sock",
}
但它已经过时了,不是吗?
But it is obsolette, isn't it?
默认样本呢?
在默认的 VS2015 示例解决方案中,他们使用了发布 iis、完整的 .NET 框架和 IIS 服务器,但没有关于在 linux 上部署的内容.
In default VS2015 sample solution they use publish-iis, Full .NET framework and IIS server, but there is nothing about deployment on linux.
postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
<小时>
这是我的 dotnet 信息
Here is my dotnet info
.NET Command Line Tools (1.0.0-preview1-002702)
Product Information:
Version: 1.0.0-preview1-002702
Commit Sha: 6cde21225e
Runtime Environment:
OS Name: Windows
OS Version: 10.0.10586
OS Platform: Windows
RID: win10-x64
.NET 核心 RC2
.NET Core RC2
推荐答案
执行以下步骤(从 RC2 便携式应用程序开始;普通的):
Do the following steps (starting from a RC2 portable application; the normal one):
删除类型":平台"来自所有依赖项的注释(因此它实际上是自包含的,不再依赖于已安装的 .NET Core 平台).
Remove the "type": "platform" annotation from all your dependencies (so it is actuall self-contained and no longer rely on a installed .NET Core platform).
将节点运行时添加到您的 project.json(以便 NuGet 能够将必要的平台部件提取到您的本地计算机)
Add a node runtimes to your project.json (so NuGet is able to pull the necessary platform parts to your local machine)
示例:
"runtimes": {
"osx.10.11-x64": { },
"win10-x64": { },
"ubuntu.14.04-x64": { }
}
dotnet restore
(确保新的运行时在本地可用).
dotnet restore
(to make sure the new runtimes are locally available).
dotnet build
(如果尚未为便携式应用程序完成)
dotnet build
(if not already done for the portable app)
dotnet publish -r ubuntu.14.04-x64
(打包)
使用能够运行应用程序的特定于平台的 dotnet 命令查看结果目录.
See the result directory with a platform specific dotnet command able to run the app.
我遵循了 .NET Core 文档中的步骤.
这篇关于.NET CLI 如何在 Linux 上发布后运行应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!