首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >dotnet发布中的错误

dotnet发布中的错误
EN

Stack Overflow用户
提问于 2022-05-27 01:02:10
回答 2查看 1.8K关注 0票数 3

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

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

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

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

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

代码语言:javascript
复制
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 

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

代码语言:javascript
复制
dotnet publish -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 --no-restore

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

代码语言:javascript
复制
dotnet build -f:net6.0-ios -c:Release /p:RuntimeIdentifier=ios-arm64 /p:BuildIpa=true

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

代码语言:javascript
复制
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文件:

代码语言:javascript
复制
<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>

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

代码语言:javascript
复制
dotnet publish -f:net6.0-ios -c:Release

必须指定设备体系结构的运行时标识符才能发布此项目。‘ios仿真器-x64’是一个仿真器架构。

代码语言:javascript
复制
dotnet build -c:Release /p:BuildIpa=true

成功,但bin/Release/net6.0-IOS/iOSarm64/ *.ipa文件中没有任何ios文件

我还删除了其他的PropertyGroup标记,但是没有什么区别。当移除第一个错误时,错误是:

错误NETSDK1013: TargetFramework值'‘未被识别。可能拼错了。如果没有,则必须显式地指定TargetFrameworkIdentifier和/或TargetFrameworkVersion属性。

而且这个项目已经不能正常加载了。

更新3:

当我从模板创建一个全新的.NET MAUI项目时,它将使用以下命令进行编译

代码语言:javascript
复制
dotnet publish -f:net6.0-ios -c:Release

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

必须指定设备体系结构的运行时标识符才能发布此项目。‘ios仿真器-x64’是一个模拟器

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

EN

回答 2

Stack Overflow用户

发布于 2022-06-15 20:04:50

我的解决方案是在Mac上运行它。不要在你的窗口机器上运行它。

目前,您可能希望安装项目的Mac和Open终端的Visual 2022预览。然后,使用sudo运行该命令。

示例:

代码语言:javascript
复制
sudo dotnet publish -f:net6.0-ios -c:Release

注意:我在毛伊岛项目中用PropertyGroup设置了我的所有属性

像个冠军一样工作!

票数 1
EN

Stack Overflow用户

发布于 2022-05-27 02:21:05

FIX 1

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

来自添加代码签名..。

.csproj:

代码语言:javascript
复制
<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>

命令行:

代码语言:javascript
复制
dotnet publish -f:net6.0-ios -c:Release

FIX 2

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

更改:

代码语言:javascript
复制
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>

至:

代码语言:javascript
复制
<TargetFrameworks>net6.0-ios</TargetFrameworks>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72399444

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档