我正在Windows 10机器上开发一个.NET Core应用程序(使用Visual Studio 2015更新3 + Microsoft .NET Core 1.0.1 VS 2015工具预览版2),这个应用程序需要在Ubuntu 16机器上发布。为了做到这一点,我必须将我的源代码移动到目标机器并在那里编译它才能运行。例如,我无法在Windows上编译代码并在Linux上运行。问题是:是否有任何方法可以在Windows机器上编译代码并在Linux上运行?
使用dotnet build命令,您可以指定--runtime
标志。
-r|--runtime < RUNTIME_IDENTIFIER >
要构建的目标运行时。您可以使用RID catalog中的Runtime Identifiers (RIDs)列表。
代表具体操作系统的RIDs通常遵循这种模式[os].[version]-[arch]
例如,要为Ubuntu 16.04 runtime构建项目及其依赖项,请使用:
dotnet build --runtime ubuntu.16.04-x64
dotnet publish **path to your solution** --configuration Release --framework netcoreapp3.0 --output .**output path** --self-contained false --runtime linux-x64 --verbosity quiet
dotnet build --runtime ubuntu.xx.xx-x64
现在需要类似这样的内容:
dotnet build ProjectName.csproj --runtime ubuntu.xx.xx-x64
无法找到与目标运行时 '.NETCoreApp,Version = v1.0' 兼容的运行时目标之一:'win10-x64,win81-x64,win8-x64,win7-x64'。
- amiry jd