简体   繁体   English

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

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

I'm trying to run my first .net core 2.0 console app on ubuntu 16.04-x64. 我正在尝试在ubuntu 16.04-x64上运行我的第一个.net核心2.0控制台应用程序。 I followed the steps to publish my app for ubuntu: 我按照步骤发布了我的ubuntu应用程序:

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

and also tried it from Visual Studio by changing my .csproj file like so: 并通过更改我的.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>

and then publish it with a publish profile. 然后使用发布配置文件发布它。

I followed the instruction from Microsoft to install .net core on ubuntu . 我按照微软的指示在ubuntu上安装.net核心 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: 当我试图运行我的控制台应用程序的.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) 

When I'm running dotnet restore I'm getting a message saying: 当我运行dotnet restore我收到一条消息说:

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? 我在这个过程中错过了一步吗?

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

This solved it for me. 这解决了我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布的控制台应用程序上没有.NET Core 2.0应用程序设置 - No .NET Core 2.0 appsettings on a published console app .Net core 2.0控制台应用程序作为Windows服务 - .Net core 2.0 console app as a windows service 从 .Net Framework 4.6.1 控制台应用程序转到 Core 2.0 控制台应用程序后出现 Newtonsoft DeserializeObject 错误 - Newtonsoft DeserializeObject error after going from .Net Framework 4.6.1 Console App to Core 2.0 console App 如何正确地为在 systemd 上运行的 Ubuntu 制作无尽的控制台应用程序 .NET Core 3.1 - How to make correctly endless console app .NET Core 3.1 for Ubuntu running on systemd 访问路径被拒绝,Asp.net core 2.0 在 Ubuntu 上运行 - Access to path is denied, Asp.net core 2.0 running on Ubuntu .Net Core 控制台应用程序未在 Docker 容器中运行 - .Net Core Console App not running in Docker container 将 .NET Core 控制台应用程序作为服务运行,还是重做? - Running .NET Core console app as a service, or redo? NET Core 2.0在vs2017中如何创建控制台应用程序? - how to create a console app in vs2017 with .net core 2.0? 阅读AppSettings数据控制台App .net Core 2.0 - Read AppSettings Data Console App .net Core 2.0 .net Core 2.0生成简单的控制台应用程序错误 - .net core 2.0 generated simple console application error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM