Ope*_*ack 19 .net c# .net-core asp.net-core dotnet-publish
我正在运行以下命令,在Windows 10 盒子上使用命令行发布 .NET CORE 5.0 Web api 项目。
c:\test\Service>dotnet publish -c release Emp.sln --framework net5.0 /p:DebugType=None /p:DebugSymbols=false --nologo --self-contained --runtime linux-x64 -v m
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
C:\ProgramFiles\dotnet\sdk\5.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targets(126,5):错误NETSDK1031:不支持构建或发布自包含应用程序而不指定运行时标识符。您必须指定 RuntimeIdentifier 或将 SelfContained 设置为 false。[c:\test\Service\emp.csproj]
为什么在指定 --runtime 标志时出现此错误?我可以使用 Visual Studio 进行发布,没有任何问题。
Ope*_*ack 27
我可以通过<RuntimeIdentifier>linux-x64</RuntimeIdentifier>在 .csproj 文件中添加行来解决该问题:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
Run Code Online (Sandbox Code Playgroud)
这样我就可以使用命令行构建解决方案,但是当在 Windows 计算机上通过 Visual Studio 运行应用程序时,我收到错误:
“emp”调试配置文件中指定的调试可执行文件“c:\user\testuser\emp\bin\debug\net5.0\linux-x64\textdb.exe”不存在
通过将其添加到 csproj 文件,我能够解决第二个问题(能够使用 Visual Studio 在 Windows 上构建并能够使用命令行发布目标 Linux)。在RuntimeIdentifiers中指定多个值
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifiers>win10-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15984 次 |
| 最近记录: |