Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core console app fails to run on Windows Server [duplicate]

I have a relatively simple .NET Core console app. It has no external dependencies. I build it using the following:

dotnet publish -c Release -r win10-x64

It generates a \bin\Release\netcoreapp2.2\win10-x64 folder structure. This folder contains the a number of files and a publish folder:

enter image description here

I copy this entire structure to a Windows Server 2016. According to the dotnet --list-runtimes commands the server has the following runtimes installed:

Microsoft.AspNetCore.All 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

However, when I run my .exe file (netcoreapp2.2\win10-x64\LayoutAutomation.exe), I get the following error:

Error:
  An assembly specified in the application dependencies manifest (LayoutAutomation.deps.json) was not found:
    package: 'runtime.win-x64.Microsoft.NETCore.App', version: '2.2.0'
    path: 'runtimes/win-x64/lib/netcoreapp2.2/Microsoft.CSharp.dll'

If I try to run the exe from the publish folder (which seemingly has the entire .NET Core installation), it runs fine.

So how can I can't run the exe from the netcoreapp2.2\win10-x64 folder? The .NET Core is installed on the box - it should run.

like image 463
AngryHacker Avatar asked Feb 05 '19 01:02

AngryHacker


1 Answers

The Publish command is one of the rare cases where Microsoft tools do what they claim to do—namely, publish the application to a specified location.

The files under the bin/release are compilation artifacts with local dependencies. Your server can't find the dependencies because those files are meant to be executed on your development machine. Those dependencies can be located in a variety of places and the compiler consolidates them in release folder.

The files under Publish are built for deployment, and depending on your publish settings, can be self-contained (default) or framework-dependent. You should copy the Publish folder's contents (or the entire folder) to your final deployment path. If you want to publish your application as framework-dependent, then modify your publish command like so:

dotnet publish -c Release -r win10-x64 --self-contained false

You can also add the -o flag to specify a deployment path.

like image 95
ATL_DEV Avatar answered Oct 25 '22 14:10

ATL_DEV