jav*_*iry 11 c# linux .net-core asp.net-core-webapi
我正在Windows 10计算机上开发.NET Core应用程序(使用Visual Studio 2015更新3 + Microsoft .NET Core 1.0.1 VS 2015工具预览2),该应用程序应该在Ubuntu 16计算机上发布.要做到这一点,我必须将我的源代码移动到最终机器并在那里编译,以使其运行.例如,我无法在Windows上编译代码并在Linux上运行它.问题:有没有办法在win机器上编译代码并在linux上运行它?
Set*_*Set 28
使用dotnet build命令,您可以指定--runtimeflag
-r | --runtime <RUNTIME_IDENTIFIER>
目标运行时构建.有关可以使用的运行时标识符(RID)的列表,请参阅RID目录.
代表具体操作系统的RID通常遵循这种模式 [os].[version]-[arch]
例如,为Ubuntu 16.04运行时使用构建项目及其依赖项:
dotnet build --runtime ubuntu.16.04-x64
Run Code Online (Sandbox Code Playgroud)
Ale*_*lex 12
dotnet build ProjectFile.csproj --runtime linux-x64
Run Code Online (Sandbox Code Playgroud)
适用于 Linux、Windows 和 Mac。
如果您愿意,还可以在 Visual Studio 中“发布”您的应用程序。选择“文件系统”发布方法并设置此设置:
dotnet publish **path to your solution** --configuration Release --framework netcoreapp3.0 --output .**output path** --self-contained false --runtime linux-x64 --verbosity quiet
Run Code Online (Sandbox Code Playgroud)
对于现在看到这不再起作用的任何人,似乎从 2020 年 11 月 10 日的更新开始,您现在必须指定项目文件,因为它不再喜欢在解决方案 (.sln) 上使用指定的运行时。
这里提出了一个关于此的问题(https://github.com/dotnet/sdk/issues/14281),但显然这不会立即得到解决。
所以以前这会起作用:
dotnet build --runtime ubuntu.xx.xx-x64
Run Code Online (Sandbox Code Playgroud)
它现在想要这样的东西:
dotnet build ProjectName.csproj --runtime ubuntu.xx.xx-x64
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23539 次 |
| 最近记录: |