【问题标题】:Errors with dotnet publishdotnet 发布错误
【发布时间】:2022-06-16 04:04:50
【问题描述】:

我使用这些资源来学习如何发布 MAUI 应用:

https://docs.microsoft.com/en-us/dotnet/maui/ios/deployment/overview

https://github.com/dotnet/maui/issues/4397

https://github.com/dotnet/sdk/issues/21877

基于这些,我尝试了不同的变体来发布,但它们都不起作用:

dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 

错误:RuntimeIdentifier 'ios-arm64' 无效。

dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 --no-restore

错误 NETSDK1032:RuntimeIdentifier 平台“ios-arm64”和 PlatformTarget 'x64' 必须兼容。

dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true

错误:RuntimeIdentifier 'ios-arm64' 无效。

dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true --no-restore

错误 NETSDK1032:RuntimeIdentifier 平台“ios-arm64”和 PlatformTarget 'x64' 必须兼容。

更新
环境:
Windows 10 家庭版 - 21H2
VS 2022 版本 17.3.0 预览版 1.1

更新 2
根据答案,我现在有这个 csproj 文件:

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

<PropertyGroup>
    <TargetFrameworks>net6.0-ios</TargetFrameworks>
    <OutputType>Exe</OutputType>
    <RootNamespace>MonkeyFinder</RootNamespace>
    <UseMaui>true</UseMaui>
    <SingleProject>true</SingleProject>
    <ImplicitUsings>enable</ImplicitUsings>

    <!-- Display name -->
    <ApplicationTitle>MonkeyFinder</ApplicationTitle>

    <!-- App Identifier -->
    <ApplicationId>com.testapp.monkeyfinder</ApplicationId>
    <ApplicationIdGuid>E46570A0-D087-4FC2-ADFE-58FEAB0BEBB9</ApplicationIdGuid>

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

    <!-- Required for C# Hot Reload -->
    <UseInterpreter Condition="'$(Configuration)' == 'Debug'">True</UseInterpreter>

</PropertyGroup>

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
    <CodesignKey>‌xxx</CodesignKey>
    <CodesignProvision>Development Test Provisioning</CodesignProvision>
            
    <ArchiveOnBuild>true</ArchiveOnBuild>
    <TcpPort>58181</TcpPort>
    <ServerAddress>xxx</ServerAddress>
    <ServerUser>xxx</ServerUser>
    <ServerPassword>xxx</ServerPassword>
    <_DotNetRootRemoteDirectory>/Users/xxx/Library/Caches/Xamarin/XMA/SDKs/dotnet/</_DotNetRootRemoteDirectory>

</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-android|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-android|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-ios|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-ios|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-maccatalyst|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-maccatalyst|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|net6.0-windows10.0.19041|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net6.0-windows10.0.19041|AnyCPU'">
  <MtouchDebug>True</MtouchDebug>
</PropertyGroup>

<ItemGroup>
    <!-- App Icon -->
    <MauiIcon Include="Resources\appicon.svg" ForegroundFile="Resources\appiconfg.svg" Color="#512BD4" />

    <!-- Splash Screen -->
    <MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" />

    <!-- Images -->
    <MauiImage Include="Resources\Images\*" />

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

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

然后我根据收集到的更多信息尝试了这些命令,结果如下:

dotnet publish -f:net6.0-ios -c:Release

必须指定设备架构的运行时标识符才能发布此项目。 'iossimulator-x64' 是一个 模拟器架构。

dotnet build -c:Release /p:BuildIpa=true

成功,但是bin/Release/net6.0-ios/ios-arm64/publish中没有*.ipa文件

我还删除了其他 PropertyGroup 标记,但没有任何区别。期望删除第一个时,错误是:

错误 NETSDK1013:无法识别 TargetFramework 值“”。它可能拼写错误。如果不是,则必须明确指定 TargetFrameworkIdentifier 和/或 TargetFrameworkVersion 属性。

而且项目也无法正确加载。

更新 3:
当我从模板创建一个全新的 .NET MAUI 项目时,它开始使用命令编译

dotnet publish -f:net6.0-ios -c:Release

但即使我将 csproj 文件中的 xml 从工作项目复制到不工作项目,我也会收到错误:

设备架构的运行时标识符必须在 为了发布这个项目。 'iossimulator-x64' 是一个模拟器

我猜这表明错误的原因实际上不是在csproj文件中找到的,而是在其他地方?

【问题讨论】:

  • 来自 Windows 还是 Mac VS?更新到最新的 VS 2022 预览版?你能从命令行buildDebug 版本吗? (没有 BuildIpa)
  • 来自 Windows,带有最新的 VS 2022 预览版。命令“dotnet build -c:Debug”运行成功。
  • 你有多个项目吗?尝试专门发布 csproj。所以 dotnet 发布 YourProject.csproj 然后是其余的选项
  • 这只是一个项目。我可能不小心弄明白了:我将标签 RuntimeIdentifier 更改为 RuntimeIdentifiers,然后它开始编译。但是现在我遇到了下一个错误:“在钥匙串中找不到代码签名密钥”

标签: maui .net-maui


【解决方案1】:

修复 1

尝试通过.csproj 中的条件属性组包含 RuntimeIdentifier,并从命令行省略

来自Add code signing ...
.csproj:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios')) and '$(Configuration)' == 'Release'">
  <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
  <CodesignKey>iPhone Distribution: John Smith (AY2GDE9QM7)</CodesignKey>
  <CodesignProvision>MyMauiApp</CodesignProvision>
  <ArchiveOnBuild>true</ArchiveOnBuild>
</PropertyGroup>

命令行:

dotnet publish -f:net6.0-ios -c:Release

修复 2

目前,当为 ios 发布时,从.csproj删除其他目标框架。注意:这不应该是必需的,因为您通过-f 指定框架,但值得一试。

变化:

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

收件人:

<TargetFrameworks>net6.0-ios</TargetFrameworks>

【讨论】:

  • 感谢您的建议。我已将结果整合到我最初的帖子中。
【解决方案2】:

我的解决方案是在 Mac 上运行它。 不要在您的 Window 机器上运行它。

目前,您可能需要安装 Visual Studio 2022 Preview for Mac 并打开项目的终端。然后,使用 sudo 运行命令。

例子:

sudo dotnet publish -f:net6.0-ios -c:Release

注意:我在 Maui 项目的 PropertyGroup 中设置了我的所有属性

像冠军一样工作!

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 1970-01-01
    • 2022-09-24
    • 1970-01-01
    • 2018-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-08-22
    • 1970-01-01
    相关资源
    最近更新 更多