【问题标题】:Error Running .net core on Debian在 Debian 上运行 .net 内核时出错
【发布时间】:2018-08-17 04:49:53
【问题描述】:

我正在尝试使用 .net 内核编译和运行我的第一个跨平台应用程序以迁移 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>

我很欣赏人们可以提供的任何见解。

【问题讨论】:

  • “我得到了每个文件夹”,这是什么文件夹?这是publish 文件夹还是另一个文件夹?
  • 尝试从 Visual Studio 构建,将 bin\Release\netcoreapp2.0 文件夹复制到 Linux,然后使用 dotnet program.dll 命令运行您的应用程序。另请参阅此问题,可能相关:github.com/dotnet/cli/issues/7543
  • @soonts 我会试试的。
  • @omajid bin\Release\netcoreapp2.0\linux-x64 和 bin\Release\netcoreapp2.0\debian-x64 分别
  • 使用发布文件夹:bin\Release\netcoreapp2.0\linux-x64\publish。这就是dotnet publish 的输出。

标签: c# .net linux debian .net-core


【解决方案1】:

当你运行时:

dotnet publish -c release -r linux-x64

您要求将此代码作为Self Contained Deployment 发布。这意味着所有 .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。

另一种方法是在Framework Dependent Deployment 模式下运行。在这种情况下,您在没有 -r linux-x64 的情况下构建。在这种情况下,您仍然复制 publish 目录,但您必须以 dotnet /path/to/your.dll 身份运行应用程序。

TLDR:部署时始终复制publish 目录。

【讨论】:

    【解决方案2】:

    @omajid 的回答很有帮助。

    请注意,如果您希望进行框架依赖部署 (FDD),则必须从 .csproj 文件中删除 &lt;RuntimeIdentifiers&gt;/&lt;RuntimeIdentifier&gt; 元素。

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

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 2019-11-28
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多