4

I've been searching for quite some time now, and can't seem to find an answer to this problem. Found only two questions/answers on SO and they still don't answer this question (https://stackoverflow.com/search?q=netcore+publish+mac+app).

I'm working with DotNetCore on Mac, using Visual Studio as the IDE. The app is a Console App, not an ASP.Net app, simple "Hello World" app in C#:

...
Console.Writeline("Hello World");
...

So here's the question... To run the app, I know I can use the "dotnet" command to run it. I'm trying to build/publish the app, as you normally would do in Windows by creating an .exe file, but now on Mac by creating a native binary file.

I have found zero documentation on how to do this, and deploy the application as a self contained app that can run independently without having to call the program using the "dotnet" command. Maybe I'm looking in the wrong places but haven't even found anything on Microsoft's documentation, they all point to documentation for building ASP.Net apps on .NetCore.

Any suggestions?

nukalov
  • 1,309
  • 13
  • 18
  • 1
    [Build .NET Core console application to output an EXE?](https://stackoverflow.com/questions/44074121/build-net-core-console-application-to-output-an-exe); [dotnet publish](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore21); [.NET Core RID Catalog](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog) – Tamás Kecskeméti Nov 03 '18 at 21:36
  • Thanks @TamásKecskeméti ! Found this command a few moments ago as well. Worked perfectly. – nukalov Nov 03 '18 at 21:45

2 Answers2

3

Found the answer by looking at the "dotnet publish" options:

dotnet publish -c Release --self-contained -r osx.10.13-x64

Where --self-contained includes all required libraries, and -r specifies the runtime target.

David Tchepak
  • 9,826
  • 2
  • 56
  • 68
nukalov
  • 1,309
  • 13
  • 18
0
$ dotnet publish -c Release --self-contained -a x64

  Determining projects to restore...
  Restored /Users/walshca/code/temp/MutexThrow/MutexThrow.csproj (in 155 ms).
  MutexThrow -> /Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/MutexThrow.dll
  MutexThrow -> /Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/publish/

dotnet publish docs

Then I run ./bin/Release/net6.0/osx-x64/publish/MutexThrow

This didn't specify the --output cli arg, so you can see in the build output it defaulted to [project_file_folder]/bin/[configuration]/[framework]/[runtime]/publish/

(In dotnet 6.0 instead of -r runtime target, you can specify --arch x86 and it uses the default RID for your system.)


If your project props sets a different build output, can you find the executable by enumerating files by unix file permissions:

$ gci -r -file | ? UnixMode -match 'x$' | % FullName
/Users/walshca/code/temp/MutexThrow/obj/Release/net6.0/osx-x64/apphost
/Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/MutexThrow
/Users/walshca/code/temp/MutexThrow/bin/Release/net6.0/osx-x64/publish/MutexThrow
Carl Walsh
  • 6,100
  • 2
  • 46
  • 50