VS Code运行.NET MAUI MacCatalyst项目提示libhostpolicy.dylib缺失的原因
问题:VS Code运行.NET MAUI MacCatalyst应用失败,VS for Mac却正常
背景
此前使用VS for Mac开发.NET MAUI应用,因VS for Mac终止服务,转而使用VS Code搭配C# Dev Kit与.NET MAUI扩展开展开发测试。已成功构建arm64架构的iOS和MacCatalyst输出产物,但运行MacCatalyst项目时出现错误。
错误信息
遇到致命错误。执行应用所需的库 'libhostpolicy.dylib' 在 '/Users/ian/Projects/BitBucket/Ledger/Ledger/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/' 中未找到。
无法以自包含应用运行。
- 应用被当作自包含应用运行,因为 '/Users/ian/Projects/BitBucket/Ledger/Ledger/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/Ledger.runtimeconfig.json' 未指定框架。
- 如果这应该是依赖框架的应用,请在 '/Users/ian/Projects/BitBucket/Ledger/Ledger/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/Ledger.runtimeconfig.json' 中指定合适的框架。
Ledger.runtimeconfig.json内容(VS for Mac与VS Code生成的完全一致)
{ "runtimeOptions": { "tfm": "net7.0", "includedFrameworks": [ { "name": "Microsoft.NETCore.App", "version": "7.0.13" }, { "name": "Microsoft.MacCatalyst", "version": "16.4.7125" }, { "name": "Microsoft.Maui.Core", "version": "**FromWorkload**" }, { "name": "Microsoft.Maui.Controls", "version": "**FromWorkload**" }, { "name": "Microsoft.Maui.Essentials", "version": "**FromWorkload**" } ], "configProperties": { "Microsoft.Extensions.DependencyInjection.VerifyOpenGenericServiceTrimmability": true, "System.AggressiveAttributeTrimming": true, "System.ComponentModel.TypeConverter.EnableUnsafeBinaryFormatterInDesigntimeLicenseContextSerialization": false, "System.Diagnostics.Debugger.IsSupported": true, "System.Diagnostics.Tracing.EventSource.IsSupported": false, "System.Globalization.Invariant": false, "System.Net.Http.EnableActivityPropagation": false, "System.Net.Http.UseNativeHttpHandler": true, "System.Reflection.NullabilityInfoContext.IsSupported": false, "System.Resources.ResourceManager.AllowCustomResourceTypes": false, "System.Resources.UseSystemResourceKeys": false, "System.Runtime.InteropServices.BuiltInComInterop.IsSupported": false, "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false, "System.StartupHookProvider.IsSupported": false, "System.Threading.Thread.EnableAutoreleasePool": true, "System.Text.Encoding.EnableUnsafeUTF7Encoding": false } } }
更新:launch.json中的MacCatalyst配置条目
{ "configurations": [ { "name": ".NET MAUI", "type": "maui", "request": "launch", "preLaunchTask": "maui: Build" }, { "name": "C#: Ledger.Tests", "type": "dotnet", "request": "launch", "projectPath": "${workspaceFolder}/UnitTests/Ledger.Tests.csproj", "launchConfigurationId": "TargetFramework=;Ledger.Tests" }, { // Use IntelliSense to find out which attributes exist for C# debugging // Use hover for the description of the existing attributes // For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md "name": "Maccatalyst", "type": "coreclr", "request": "launch", "preLaunchTask": "build", "targetArchitecture": "arm64", // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/Ledger/bin/Debug/net7.0-maccatalyst/maccatalyst-arm64/Ledger.dll", "args": [], "cwd": "${workspaceFolder}/Ledger", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console "console": "internalConsole", "stopAtEntry": false } ] }
为何VS for Mac可正常启动并运行该MacCatalyst应用,而VS Code却不行?
内容的提问来源于stack exchange,提问作者Lamotu
相关产品推荐
相关产品推荐

