在 ubuntu 上运行控制台应用程序时出现 .net core 2.0 错误

Lir*_*man 6 c# ubuntu .net-core asp.net-core

我正在尝试在 ubuntu 16.04-x64 上运行我的第一个 .net core 2.0 控制台应用程序。我按照以下步骤为 ubuntu 发布我的应用程序:

dotnet publish -c release -r ubuntu.16.04-x64
Run Code Online (Sandbox Code Playgroud)

并通过更改我的 .csproj 文件从 Visual Studio 尝试它,如下所示:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>ubuntu.16.04-x64</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="sharpadbclient" Version="2.1.0" />
    <PackageReference Include="System.IO.Ports" Version="4.4.0" />
  </ItemGroup>

</Project>
Run Code Online (Sandbox Code Playgroud)

然后使用发布配置文件发布它。

我按照 Microsoft 的说明在 ubuntu 上安装 .net core。当我尝试运行控制台应用程序的 .dll 文件时,我将发布的输出复制到运行 ubuntu ans 的 PC 我收到此错误:

Unhandled Exception: System.IO.FileLoadException: 
Could not load file or assembly
'System.Console, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
The located assembly's manifest definition does not match the assembly reference.
(Exception from HRESULT: 0x80131040)
   at LinuxVersion.Program.InitializeComponent()
   at LinuxVersion.Program.Main(String[] args)
Aborted (core dumped) 
Run Code Online (Sandbox Code Playgroud)

当我跑步时,dotnet restore我收到一条消息:

MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
Run Code Online (Sandbox Code Playgroud)

我在这个过程中遗漏了一个步骤吗?

Lir*_*man 5

好吧,事实证明使用 Visual Studio 发布配置文件(右键单击项目并选择“发布”)和使用命令行发布应用程序之间存在差异。当我使用 Visual Studio 发布配置文件时出现此错误,然后我切换到使用命令行,如下所示:dotnet publish -c release -r ubuntu.16.04-x64 但要运行它,我进入了输出的发布文件夹:cd /home/MyApp/publish然后使用dotnet MyAppName.dll.

这为我解决了它。