使用 VSCode“Platform/Android/google-services.json”构建 .Net MAUI 应用程序将导致文件位于应用程序包之外且无法使用

问题描述 投票:0回答:1

当尝试使用 VSCode 构建 .Net 8.0 MAUI 应用程序以在 Mac 上调试 iOS 18 模拟器时,出现以下错误:

Platforms/Android/google-services.json : error : The path '../../../../../../../../../Users/user/MyMauiApp/Platforms/Android/google-services.json' would result in a file outside of the app bundle and cannot be used. [/Users/user/MyMauiApp/MyMauiApp.csproj::TargetFramework=net8.0-ios]

Platforms/Android/google-services.json : error :          [/Users/user/MyMauiApp/MyMauiApp.csproj::TargetFramework=net8.0-ios]

我在 android 构建条件下的 .csproj 中引用了该文件:

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android'">
   <PackageReference Include="Xamarin.AndroidX.Core" Version="1.12.0.4" />
   <PackageReference Include="Xamarin.AndroidX.Collection" Version="1.4.0.2" />
   <PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.0.1" />
   <PackageReference Include="Xamarin.AndroidX.Activity.Ktx" Version="1.8.2.1" />
   <GoogleServicesJson Include="Platforms\Android\google-services.json" />
</ItemGroup>

没有其他地方。我尝试将其从 iOS 构建中排除:

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
  <PackageReference Include="Xamarin.Firebase.iOS.Core" Version="8.10.0.3" />
  <BundleResource Include="Platforms\iOS\GoogleService-Info.plist" Link="GoogleService-Info.plist" />
  <None Remove="Platforms/Android/google-services.json" />
</ItemGroup>

仍然出现错误。我团队的其他成员也遇到了同样的错误,并且找不到解决方法。当我们在 Windows 设备上使用 Visual Studio 2022 为 Android 构建时,不会发生该错误。我不确定接下来要尝试什么。

macos visual-studio-code maui vscode-debugger maui-blazor
1个回答
0
投票

请尝试修改以下代码,将您的

<ItemGroup Condition="'$(TargetFramework)' != 'net8.0-android'">
中的
<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
改为
.csproj.json

  <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-ios'">
    <PackageReference Include="Xamarin.Firebase.iOS.Core" Version="8.10.0.3" />
    <BundleResource Include="Platforms/iOS/GoogleService-Info.plist" Link="GoogleService-Info.plist" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' != 'net8.0-android'">
    <None Remove="Platforms/Android/google-services.json" />
  </ItemGroup>

编辑 json 文件后,请确保清理您的解决方案并重建它:

dotnet clean
dotnet build
© www.soinside.com 2019 - 2024. All rights reserved.