.net Core 2.0错误在Ubuntu上运行控制台应用程序 [英] .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
,但要运行它,我进入了输出的publish文件夹: cd / home / MyApp / publish
,然后使用<$ c运行应用程序$ c> 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
.
这为我解决了。
这篇关于.net Core 2.0错误在Ubuntu上运行控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!