amiry jd
amiry jd

Reputation: 27603

How to compile .NET Core app for Linux on a Windows machine

I'm developing a .NET Core app on a Windows 10 machine (with Visual Studio 2015 update 3 + Microsoft .NET Core 1.0.1 VS 2015 Tooling Preview 2) which should published on an Ubuntu 16 machine. To do that, I have to move my source code to the end machine and compile it there, to get it to run. e.g. I'm not able to compile the code on windows and run it on linux. Question: Is there any way to compile the code on win machine and run it on linux?

Upvotes: 61

Views: 161001

Answers (5)

uingtea
uingtea

Reputation: 6554

2024, you can directly copy the files to your linux host:

myapp.dll
myapp.runtimeconfig.json

note: myapp.exe is not needed

then to run the app

dotnet myapp.dll

Upvotes: 1

Alex from Jitbit
Alex from Jitbit

Reputation: 60862

Option 1: Command line

dotnet build ProjectFile.csproj --runtime linux-x64

Works on Linux and Windows and Mac.

Option 2: Visual Studio

You can also "publish" your app in Visual Studio if you prefer. Choose "File System" publish method and set this setting:

enter image description here

Upvotes: 16

Rogod
Rogod

Reputation: 198

For anyone who's now seeing this not working anymore, it seems as of the update on the 10th of November 2020 you have to specify the project file now as it doesn't like using a specified runtime on a solution (.sln) anymore.

An issue about this was raised here (https://github.com/dotnet/sdk/issues/14281) but obviously that's not going to get resolved immediately.

So previously where this would work:

dotnet build --runtime ubuntu.xx.xx-x64

It wants something like this now:

dotnet build ProjectName.csproj --runtime ubuntu.xx.xx-x64

Upvotes: 12

Wasyster
Wasyster

Reputation: 2535

dotnet publish **path to your solution** --configuration Release --framework netcoreapp3.0 --output .**output path** --self-contained false --runtime linux-x64 --verbosity quiet

Upvotes: 13

Set
Set

Reputation: 49789

Using dotnet build command, you may specify --runtime flag

-r|--runtime < RUNTIME_IDENTIFIER >

Target runtime to build for. For a list of Runtime Identifiers (RIDs) you can use, see the RID catalog.

RIDs that represent concrete operating systems usually follow this pattern [os].[version]-[arch]

Fo example, to build a project and its dependencies for Ubuntu 16.04 runtime use:

dotnet build --runtime ubuntu.16.04-x64

Upvotes: 74

Related Questions