Build, Notarize and Sign .NET console application for Mac OS
Published on June 02, 2021 by Coding Flamingo
MacOS CI/CD Build pipeline Sign Notarize Build
5 min READ
Since the introduction of MacOS BigSur, Apple requires all software that runs on a Mac to be signed by a certificate from a developer in their developer program and notarized. In this blog we will go through how to do this for a .NET Console application.
First thing we have to do is create your apple developer certificate.
base64 YOURCERTFILENAME.p12
Your Apple Developer account has MFA, so we have create a password for the GitHub action to use to notarize the application.
TL;DR here is the GitHub Action, you are going to need this script + this file to sign and this script to notarize.
This Action Has to Run on MacOS NOTE: MacOS GitHub action minutes cost 10x regular minutes.
We also have to use dotnet 6. It is the only one that supports notarizing for MacOS. (this blog was written before it was GA, so the include-prerelease has to set to true.
name: MAC Signing
on:
workflow_dispatch:
jobs:
build:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Set up .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6.0.x'
include-prerelease: true
we then run dotnet publish for Mac OS where “ConsoleApp1/ConsoleApp1.csproj” is the path to your csproj.
Note we are running this for osx-x64 you can change this for the new arm machines as well
- name: dotnet publish
run: dotnet publish ConsoleApp1/ConsoleApp1.csproj -c Release -r osx-x64 -p:UseAppHost=true -p:PublishSingleFile=true --self-contained true -p:PublishReadyToRunShowWarnings=true -o $/consoleapp
Note: we set the output of the publish to $/consoleapp
now we delete the .pdb files, since they are not used.
- name: delete .pdb
run: rm $/consoleapp/*.pdb
Then we make the console application file executable by runinning where “ConsoleApp1” is your file name.
- name: chmod
run: chmod +x $/consoleapp/ConsoleApp1
Now we have to add the certificate to the keychain to use it to sign the application.
- name: Add Cert to Keychain
uses: apple-actions/import-codesign-certs@v1
with:
p12-file-base64: $
p12-password: $
Then we run this signing script passing the following variables:
- name: Sign Binaries
run: "sh BuildAndReleaseScripts/SignMac.sh \"$/consoleapp/ConsoleApp1\" \"$/consoleapp/*\" \"Developer ID Application: CodingFlamingo (HVPR40Y9IG)\" \"BuildAndReleaseScripts/entitlements.plist\""
Then we have to zip the folder to send it to Apple to notarize it:
- name: Zip Binary for Notarizing
run: zip -rj consoleapp.zip $/consoleapp/*
Then we send it to Apple to get notarized with this script passing the following variables:
- name: Notarize Binaries
run: "sh BuildAndReleaseScripts/Notarize.sh \"codingflamingo@gmail.com\" \"$\" \"group.com.codingflamingo\" \"HVPR40Y9IG\" \"./consoleapp.zip\""
Finally we upload the artifacts.
- name: Upload artifact for deployment job
uses: actions\upload-artifact@v2
with:
name: MyConsoleApp-MacOS
path: $/consoleapp
And that is how you Build, Sign, and Notarize .NET console app for MacOS.
Comments
No comments found for this article.
Join the discussion for this article by commenting in this ticket. Comments appear on this page instantly.