2

I'm learning how to deploy .NET Core applications to multiple platforms, and I am unable to produce a .dmg executable for the Mac OS.

This is my development environment:

  • Windows 10 Professional 64 bit
  • Visual Studio 2017 Professional with latest update
  • Targeting .NET Core 2.1

To test the deployment process, I created a simple "hello world" .NET Core Console App. I followed the steps on the official MSDN website to deploy the application to Mac OS in Visual Studio as a Self Contained Deployment package, but I don't see a .dmg file in the published target directory. I only see .dll files and other project related files. I also tried to publish to the Mac OS as a Self Contained Deployment package via the .NET Core CLI by issuing the following commands, but that still did not produce the .dmg executable:

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

I also tried:

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

How do I create the .dmg executable?

Thanks.

Raj Narayanan
  • 2,443
  • 4
  • 24
  • 43
  • 1
    I can't answer the direct question, but I have a correction for how you're thinking about it: a .dmg file is not an executable, it is a container format, a bit like a .zip or maybe .iso. It's used to protect an actual executable (or installer package, or whatever) as it's distributed/transferred/stored/etc. – Gordon Davisson Apr 06 '19 at 21:04

1 Answers1

2

A .dmg is not an executable, it's a disk image (as Gordon wrote, something like an .iso). It can be used for distributing software, and I wouldn't expect your tools to output a .dmg (nor do Apple's own development tools).

"Self contained deployment" package in this case means that the .NET runtime is statically linked inside your executable, so the end user does not need the .NET runtime installed (at the cost of increasing the size of your binary). See self-contained. NET core applications.

Your build should be producing an MACH binary (probably with the same name as your project, without any extension). You can distribute this binary how you like, including using a .dmg. You can use hdiutil to create and manipulate Apple disk images.

TheNextman
  • 12,428
  • 2
  • 36
  • 75
  • Nicely explained. I do see the elf file with no extension in the publish directory. Is this the actual executable file for the Mac which the deployment method produced? Do I just rename this file to apend the `.app` extension and then use this file to create the `.dmg` image with hdiutil? – Raj Narayanan Apr 07 '19 at 15:09
  • 1
    No. A .app is a "package" of various files (the executable, resources, etc). See https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html. There's no reason you shouldn't be able to create an .app for your executable, but you will need to create the correct structure. – TheNextman Apr 07 '19 at 19:25
  • 1
    Minor correction: macOS uses the [Mach-O](https://en.wikipedia.org/wiki/Mach-O) format for executables, not elf. – Gordon Davisson Apr 08 '19 at 07:29
  • Thanks, fixed @GordonDavisson – TheNextman Apr 08 '19 at 17:55