在 macOS 中執行 .NET 應用 - 以 GStreamerPlayer 為例

在 iThome 舉辦的 iTHelp 2025 鐵人賽當中發表的 "莫名其妙就跟世界等級的 OpenSource 專案攪和了!?" 系列文中 "EP 30 - .NET + AvaloniaUI + GStreamer 跨平台" 裡,有展示了在 macOS 當中使用 GStreamerPlayer 的應用程式 (透過 .NET + Avalonia UI + GStreamer 的技術),來透過 GStreamer 的技術播放影片。


 

在 macOS 上,僅單純的安裝好 .NET 與 GStreamer 的執行環境。

 

而此 GStreamerPlayer 的 .NET 應用則是在 Windows 當中透過 Visaul Studio 開發完成,並透過 dotnet publish 的指令進行專案的 publish 後,再把 publish 出來的檔案資料放到 macOS 當中,透過 dotnet 來執行此 GStreamerPlayer 的應用。

 

指定 runtime 為 "osx-arm64" (個人使用的 Mac 機器是 M4 的 CPU,所以選擇 arm64);configuration 為 "Release" (預設為 Release;在 .NET 6 以前預設值為 Debug):

dotnet publish .\GStreamerPlayer.csproj --runtime osx-arm64 --configuration Release
runtime 可使用的設定值可參考 ".NET RID 目錄 - 已知 RID"。

 

編譯建置中:

 

發佈建置完成:

 

在 publish 當中沒有指定 --output 的路徑狀況下,根據上述說明預設會在專案資料夾的 "bin/Release/net8.0/osx-arm64/publish" 這個資料夾:

整個 publish 資料夾複製到 macOS 上後:

 

接著輸入給 DYLD_LIBRARY_PATH 的暫時性環境變數:
"DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH"

即可透過 "dotnet GStreamerPlayer.dll" 啟動應用:

 

GStreamerPlayer 應用執行:


 


I'm a Microsoft MVP - Developer Technologies (From 2015 ~).
 

MVP_Logo



I focus on the following topics: Xamarin Technology, Azure, Mobile DevOps, and Microsoft EM+S.

If you want to know more about them, welcome to my website:
https://jamestsai.tw 


本部落格文章之圖片相關後製處理皆透過 Techsmith 公司 所贊助其授權使用之 "Snagit" 與 "Snagit Editor" 軟體製作。