Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.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. I followed the steps to publish my app for ubuntu:

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

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.

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) 

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?

like image 619
Liran Friedman Avatar asked Sep 17 '17 13:09

Liran Friedman


1 Answers

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.

This solved it for me.

like image 101
Liran Friedman Avatar answered Oct 10 '22 19:10

Liran Friedman