“必须启用代码签名才能创建 Xcode 存档。”在 .NET MAUI 中发布 Android 时

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

我正在使用 C# 8.0 在 .NET MAUI 中开发一个应用程序,我的第一个构建被 Google 和 Apple 拒绝。我能够更新项目配置,以便我可以为 Apple 创建一个 *.ipa 文件,他们似乎对此很满意。不过,现在我不再为 Google 构建 Bundle。

我选择一台物理 Android 设备作为目标,然后选择发布配置。当我右键单击我的项目并从上下文菜单中选择“发布...”时,它会启动构建。它显示 Android 作为目标平台,这是正确的,并且进程文本显示“Archiving App Bundle”,这也很好。但是构建失败并且显示的消息是:

>C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk.net8.0_18.0\18.0.8303\tools\msbuild\iOS\Xamarin.Shared.targets(2901,3): error : Code signing must be enabled to create an Xcode archive.

现在的问题是:我正在为 Android 而不是 iOS 制作此版本。那么,为什么要涉及 XCode?

请在下面找到我稍微编辑过的项目文件。

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFrameworks>net8.0-ios;net8.0-maccatalyst;net8.0-android34.0</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks>

        <OutputType>Exe</OutputType>
        <RootNamespace>[MY APP NAME]</RootNamespace>
        <UseMaui>true</UseMaui>
        <SingleProject>true</SingleProject>
        <ImplicitUsings>disable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <!-- Display name -->
        <ApplicationTitle>[MY APP NAME]</ApplicationTitle>

        <!-- App Identifier -->
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

        <!-- Versions -->
        <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
        <ApplicationVersion>1</ApplicationVersion>

        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">12.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">13.1</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">27.0</SupportedOSPlatformVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
        <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
        <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
    </PropertyGroup>

    <PropertyGroup Condition="'$(TargetFramework)'=='net8.0-ios'">
        <ProvisioningType>manual</ProvisioningType>
        <CodesignKey>[MY VALID KEY]</CodesignKey>
        <CodesignProvision>[MY VALID PROVISION]</CodesignProvision>
    </PropertyGroup>

    <!-- iOS -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-ios|AnyCPU'">
        <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
        <CodesignResourceRules></CodesignResourceRules>

        <MtouchDebug>True</MtouchDebug>
        <ArchiveOnBuild>True</ArchiveOnBuild>
        <MtouchInterpreter>all</MtouchInterpreter>
        <PublishAot>False</PublishAot>
        <UseInterpreter>True</UseInterpreter>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-ios|AnyCPU'">
        <CodesignEntitlements>Platforms\iOS\Entitlements.plist</CodesignEntitlements>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
        <CodesignResourceRules></CodesignResourceRules>

        <MtouchDebug>True</MtouchDebug>
        <ArchiveOnBuild>True</ArchiveOnBuild>
        <MtouchInterpreter>all</MtouchInterpreter>
        <PublishAot>False</PublishAot>
        <UseInterpreter>True</UseInterpreter>
    </PropertyGroup>

    <!-- Android -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-android34.0|AnyCPU'">
        <AndroidPackageFormat>aab</AndroidPackageFormat>
        <Debugger>Xamarin</Debugger>
        <EnableLLVM>False</EnableLLVM>
        <AndroidUseAapt2>True</AndroidUseAapt2>
        <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

        <_MauiForceXamlCForDebug>True</_MauiForceXamlCForDebug>
        <UseInterpreter>False</UseInterpreter>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-android34.0|AnyCPU'">
        <EmbedAssembliesIntoApk>True</EmbedAssembliesIntoApk>
        <Debugger>Xamarin</Debugger>
        <EnableLLVM>False</EnableLLVM>
        <AndroidUseAapt2>True</AndroidUseAapt2>
        <AndroidCreatePackagePerAbi>False</AndroidCreatePackagePerAbi>
        <AndroidPackageFormat>aab</AndroidPackageFormat>
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>

        <_MauiForceXamlCForDebug>True</_MauiForceXamlCForDebug>
        <UseInterpreter>False</UseInterpreter>
    </PropertyGroup>

    <!-- Mac Catalyst -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-maccatalyst|AnyCPU'">
      <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-maccatalyst|AnyCPU'">
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <!-- Windows -->
    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net8.0-windows10.0.19041.0|AnyCPU'">
        <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net8.0-windows10.0.19041.0|AnyCPU'">
      <ApplicationId>[MY APP IDENTIFIER]</ApplicationId>
    </PropertyGroup>

    <ItemGroup>
        <!-- App Icon -->
        <MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\ourappicon.png" Color="#C7DCF9" />

        <!-- Splash Screen -->
        <MauiSplashScreen Include="Resources\Images\app_our_logo.png" Color="#C7DCF9" BaseSize="200,67" />

        <!-- Images -->
        <MauiImage Include="Resources\Images\*" />
        <MauiImage Update="Resources\Images\app_our_logo.png">
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </MauiImage>

        <!-- Custom Fonts -->
        <MauiFont Include="Resources\Fonts\*" />

        <!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
        <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
    </ItemGroup>

    <ItemGroup>
        <None Remove="appsettings.json" />
    </ItemGroup>

    <ItemGroup>
        <EmbeddedResource Include="appsettings.json" />
    </ItemGroup>

    <ItemGroup Condition="$(TargetFramework.Contains('-ios'))">
        <CustomEntitlements Include="aps-environment" Type="string" Value="development" Condition="'$(Configuration)' == 'Debug'" />
        <CustomEntitlements Include="aps-environment" Type="string" Value="production" Condition="'$(Configuration)' == 'Release'" />
    </ItemGroup>
    <ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios' OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">
        <BundleResource Include="Platforms\iOS\PrivacyInfo.xcprivacy" LogicalName="PrivacyInfo.xcprivacy" />
    </ItemGroup>

    <ItemGroup>
        <GoogleServicesJson Include="Platforms\Android\google-services.json" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Camera.MAUI" Version="1.5.1" />
        <PackageReference Include="Camera.MAUI.ZXing" Version="1.0.0" />
        <PackageReference Include="CommunityToolkit.Maui" Version="9.0.3" />
        <PackageReference Include="CommunityToolkit.Maui.MediaElement" Version="4.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
        <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
        <PackageReference Include="Microsoft.Maui.Controls" Version="8.0.91" />
        <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="8.0.91" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="Plugin.LocalNotification" Version="11.1.3" />
        <PackageReference Include="Shiny.Beacons" Version="3.3.3" />
        <PackageReference Include="Shiny.Hosting.Maui" Version="3.3.3" />
        <PackageReference Include="Shiny.Push" Version="3.3.3" />
    </ItemGroup>

    <ItemGroup>
        <!-- ... Here are two C# 8.0 library projects I am using ... -->
    </ItemGroup>

    <ItemGroup>
        <!-- ... All my non-image resources are here ... -->
    </ItemGroup>

    <ItemGroup>
        <MauiXaml Update="Resources\Styles\CommonStyles.xaml">
            <Generator>MSBuild:Compile</Generator>
        </MauiXaml>
    </ItemGroup>

    <ItemGroup>
        <!-- ... All my XAML files are here ... -->
    </ItemGroup>

    <ItemGroup Condition="'$(TargetFramework)' == 'net8.0-android34.0'">
        <PackageReference Include="Symbol.XamarinEMDK">
            <Version>8.0.0.9</Version>
        </PackageReference>
    </ItemGroup>

</Project>
xamarin maui
1个回答
0
投票

我在今天早上的地铁通勤中想到了一个想法,虽然可行,但感觉并不令人满意。我备份了应用程序的项目文件,然后从项目文件中删除了对 iOS 或 Mac 的任何引用。这确保了 Visual Studio 不会尝试使用 XCode 执行任何操作,因为实际上没有留下任何对 iOS 的引用。

我能够毫无问题地创建一个新的捆绑包。令人惊讶的是,创建的 Bundle 比我两周前构建的最后一个 Bundle 小 60% 以上。唯一改变的是我减少的配置。

如果有人有更好的选择并且我可以使用单个配置文件,我会非常高兴。

© www.soinside.com 2019 - 2024. All rights reserved.