簡體   English   中英

.net core 2.0錯誤在ubuntu上運行控制台應用程序

[英].net core 2.0 error running console app on ubuntu

我正在嘗試在ubuntu 16.04-x64上運行我的第一個.net核心2.0控制台應用程序。 我按照步驟發布了我的ubuntu應用程序:

dotnet publish -c release -r ubuntu.16.04-x64

並通過更改我的.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>

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

我按照微軟的指示在ubuntu上安裝.net核心 當我試圖運行我的控制台應用程序的.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) 

當我運行dotnet restore我收到一條消息說:

MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.

我在這個過程中錯過了一步嗎?

好吧,事實證明,使用Visual Studio發布配置文件(右鍵單擊項目並選擇“發布”)和使用命令行發布應用程序之間存在差異。 當我使用Visual Studio發布配置文件時出現此錯誤,然后我切換到使用命令行,如下所示: dotnet publish -c release -r ubuntu.16.04-x64但運行它我進入了輸出的發布文件夾: cd /home/MyApp/publish然后使用dotnet MyAppName.dll運行應用程序。

這解決了我。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM