6

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?

Liran Friedman
  • 4,027
  • 13
  • 53
  • 96
  • Where exactly are you running dotnet restore command? – Ibro Sep 17 '17 at 14:06
  • On the target PC which is running ubuntu – Liran Friedman Sep 17 '17 at 14:35
  • 2
    Are you using `./yourappname` to run the published app or `dotnet yourappname.dll`? since this is a self-contained deployment, it is likely that only the first one will work - and even then you should use `linux-x64` for .net core 2.0 instead of `ubuntu*` – Martin Ullrich Sep 17 '17 at 14:54
  • I was actually using the second approach `dotnet myappname.dll` but I'll try the first approach you suggested. Do you think this may be the cause to this specific error? Also, what did you mean by: use `linux-x64` instead of `ubuntu*`? Did you mean in the `dotnet publish` command? – Liran Friedman Sep 17 '17 at 17:32
  • Possible duplicate of [Running Self-contained ASP .NET core application on Ubuntu](https://stackoverflow.com/questions/40226032/running-self-contained-asp-net-core-application-on-ubuntu) – Harit Kumar Oct 23 '17 at 13:39

1 Answers1

7

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.

Liran Friedman
  • 4,027
  • 13
  • 53
  • 96