在Debian上运行.NET Core时出现错误

4
我将尝试使用 .NET Core 编译和运行第一个跨平台应用程序,以迁移 C# 应用程序。我正在 Debian stretch 9.3 上进行尝试。
我已经运行了以下两个命令:
dotnet build -r debian-x64
dotnet publish -c release -r debian-x64

dotnet build -r linux-x64
dotnet publish -c release -r linux-x64

我针对这两个文件夹做了备份(bin\Release\netcoreapp2.0\linux-x64和bin\Release\netcoreapp2.0\debian-x64),使用SFTP工具将它们传输到我的Linux服务器。在Linux系统中,我通过cd命令进入相应的文件夹,并运行 .\program 命令。 当我尝试使用特定于Debian或通用Linux的编译代码时,出现以下错误:
Error:
  An assembly specified in the application dependencies manifest (nfz_core.deps.json) was not found:
    package: 'runtime.linux-x64.Microsoft.NETCore.App', version: '2.0.0'
    path: 'runtimes/linux-x64/lib/netcoreapp2.0/Microsoft.CSharp.dll'

我觉得我可能在我的csproj文件中做错了什么,但是我似乎无法弄清楚我做错了什么。
这是我的.csproj文件。
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;debian-x64;linux-x64</RuntimeIdentifiers>
  </PropertyGroup>

</Project>

我感激大家能提供任何见解。

尝试从Visual Studio构建,将bin\Release\netcoreapp2.0文件夹复制到Linux,并使用dotnet program.dll命令运行您的应用程序。另外请参阅此问题,可能相关:https://github.com/dotnet/cli/issues/7543 - Soonts
@soonts 我会尝试的。 - mberna
@omajid bin\Release\netcoreapp2.0\linux-x64 和 bin\Release\netcoreapp2.0\debian-x64 分别是什么意思。 - mberna
请使用发布文件夹:bin\Release\netcoreapp2.0\linux-x64\publish。这是 dotnet publish 命令的输出目录。 - omajid
非常感谢大家,问题已经解决了。我以为它是自包含的,但我只是使用了错误的文件夹。请将此作为答案发布,以便我可以给予认可。 - mberna
显示剩余3条评论
2个回答

2
当你运行时:
dotnet publish -c release -r linux-x64

您正在要求将此代码发布为自包含部署。这意味着.NET Core运行时、所有依赖项以及基本上与操作系统无关的所有内容都将与您的应用程序一起发布。发布命令将您的构建放置在:
bin\Release\netcoreapp2.0\linux-x64\publish

注意:这与bin\Release\netcoreapp2.0\linux-x64\不同。 linux-x64目录包含dotnet build的输出,而不是dotnet publish
一旦复制了publish目录,您可以在目标操作系统上直接运行程序(./program),而无需安装.NET Core。
另一种选择是以框架相关部署模式运行。在这种情况下,您不需要使用-r linux-x64进行构建。您仍然需要复制publish目录,但必须将应用程序作为dotnet /path/to/your.dll运行。
TLDR:部署时始终复制publish目录。

0

@omajid的回答很有帮助。

请注意,如果您希望进行Framework Dependent Deployment(FDD),则必须从.csproj文件中删除<RuntimeIdentifiers>/<RuntimeIdentifier>元素。

这样的FDD更小,因为它们不捆绑*.soSystem.*.dll文件。例如,对于一个最小的项目,您可能只需要部署四个文件(如果排除*.pdb调试文件,则为三个)。这些部署在运行时之间是可移植的。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接