在 ubuntu 上运行控制台应用程序时出现 .net core 2.0 错误 [英] .net core 2.0 error running console app on ubuntu
问题描述
我正在尝试在 ubuntu 16.04-x64 上运行我的第一个 .net core 2.0 控制台应用程序.我按照以下步骤为 ubuntu 发布我的应用程序:
I'm trying to run my first .net core 2.0 console app on ubuntu 16.04-x64. I followed the steps to publish my app for ubuntu:
dotnet publish -c release -r ubuntu.16.04-x64
并且还通过像这样更改我的 .csproj 文件从 Visual Studio 尝试它:
and also tried it from Visual Studio by changing my .csproj file like so:
<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>
然后使用发布配置文件发布它.
and then publish it with a publish profile.
我按照 Microsoft 的说明在 ubuntu 上安装 .net 核心.当我尝试运行控制台应用程序的 .dll 文件时,我将发布的输出复制到运行 ubuntu ans 的 PC 我收到此错误:
I followed the instruction from Microsoft to install .net core on ubuntu. I copied the published output to the PC running ubuntu ans when I'm trying to run the .dll file of my console app I'm getting this error:
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
时,我收到一条消息:
When I'm running dotnet restore
I'm getting a message saying:
MSBUILD : error MSB1003: Specify a project or solution file.
The current working directory does not contain a project or solution file.
我是否在此过程中遗漏了一个步骤?
Am I missing a step here in the process?
推荐答案
嗯,事实证明使用 Visual Studio 发布配置文件(右键单击项目并选择发布")和使用命令发布应用程序之间存在差异线.当我使用 Visual Studio 发布配置文件时出现此错误,然后我切换到使用命令行,如下所示:dotnet publish -c release -r ubuntu.16.04-x64
但是为了运行它,我进入了输出的发布文件夹:cd/home/MyApp/publish
然后使用 dotnet MyAppName.dll
运行应用程序.
Well, turns out there is a difference between publishing the app using Visual Studio publish profile (right clicking on the project and selecting "publish") and using the command line.
When I used the Visual Studio publish profile I got this error, then I switched to using the command line like so: dotnet publish -c release -r ubuntu.16.04-x64
but to run it I went into the publish folder of the output: cd /home/MyApp/publish
and then run the app using dotnet MyAppName.dll
.
这为我解决了.
这篇关于在 ubuntu 上运行控制台应用程序时出现 .net core 2.0 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!