可能是一个简单的问题,但很难找到相关信息。
我可以使用以下命令从 CLI 构建一个测试应用程序:
dotnet publish -c Release -r rhel.7.2-x64
Run Code Online (Sandbox Code Playgroud)
注意 -r 标志,它告诉 dotnet 为 redhat 7.2 构建它。这很好用。
在通过 VS 构建/调试时,如何让 Visual Studio 添加 -r 标志?我的第一直觉是使用 global.json 文件,但这只能让我更改 SDK 运行时,而不是目标运行时。任何想法都会很棒。
为了完整起见,我正在使用 redhat dotnet 2.0 运行时映像对应用程序进行 dockerizing,因此我需要将 bin 文件作为该构建的目标。
将 RuntimeIdentifiers XML 元素添加到 .csproj 文件。用分号分隔多个标识符。像这样:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
<TargetFramework>netcoreapp2.0</TargetFramework>
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win-x64;rhel.7.2-x64</RuntimeIdentifiers>
...
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
在 Visual Studio 中,右键单击项目 > 发布 > 选择目标运行时。