Xamarin

我的 Xamarin iOS 生成从解决方案文件 ( .sln) 而不是 ( .csproj 的项目文件)

当你的 Xamarin iOS 版本从解决方案文件 ( .sln) 运行时,你可能需要检查以下几项。

对于适用于 iOS 生成的生成配置,应在代码中禁用 Android 和 UWP 项目。 进入解决方案的配置映射,对于针对 iPhone 和 iPhoneSimulator 的所有映射,取消选中面向不同平台的所有项目。 此配置可确保 .sln 开始生成时不会尝试生成其他项目。

我的 Xamarin iOS 生成失败,需要提供签名信息

如果你的 Xamarin iOS 版本未签名,但生成过程需要签名,则很可能是因为你 Sign builds: Off 在 App Center 分支配置中选择了。

如果生成日志包含:

RequireProvisioningProfile: True. 

这意味着,即使 App Center 配置,项目本身也已配置为进行签名和应用签名。

若要修复此问题,请打开 Project 选项 > 在 IDE 中生成 > iOS 捆绑签名,并确保项目配置 (例如,Debug | iPhoneSimulator) 不包含除 "自动" 以外的任何签名信息。

我的 Xamarin 版本失败,出现 错误:找不到 APK 文件

Xamarin Android Postprocess 任务中生成失败的一个常见原因是 Android 项目文件的属性中的值不正确 <OutputPath> 。 若要进行检查,请前往 Xamarin > Project 选项 > 生成 > 输出,并验证生成配置 (调试/发布) 指向默认位置。 通常情况下,它应该是 YourProjectDir/bin/$(Configuration)

我将我的 Xamarin iOS 应用分支设置为生成而不签名,但我的生成未通过申报需要提供签名信息

如果 Sign builds: Off 在 App Center 分支配置中选择了,并且生成日志包含 RequireProvisioningProfile: True ,则表示你的项目本身已配置为进行签名,并将尝试应用签名,而不管 App Center 配置。 若要修复此问题,请打开 Project 选项 > 在 IDE 中生成 > iOS 捆绑签名,并确保项目配置 (例如, Debug | iPhoneSimulator) 不包含除 "自动" 以外的任何签名信息。

在 Xamarin iOS 应用程序中禁用调试配置签名

我的 Xamarin 模拟器生成无法安装到 iOS 模拟器,其 "无法 chmod/Appname.iOS.app/Appname.iOS:无此文件或目录" 错误。

在 Visual Studio 中创建 Xamarin iOS 项目时,iPhoneSimulator 的默认配置具有 i386 + x86_64 支持的体系结构。 从这种配置生成的 app.config 文件将无法上传到模拟器。 打开 Project 选项 "> 生成 > iOS 生成" 和 "将 支持的体系结构" 更改为 " i386 " 或 " x86_64"。

在 Xamarin iOS 应用程序的 iPhoneSimulator 配置支持的体系结构中设置 x86_64

我的 Xamarin 生成失败,并出现错误 MSB4018: "WriteRestoreGraphTask" 任务意外失败。

类似于你的解决方案,其中包含 PCL 或更早的 .NET Standard 项目以及较新的 .NET Standard 项目。 这意味着它们可能包含 PackageTargetFallback AssetTargetFallback 文件中的和引用 .csproj 。 生成日志还将包含如下消息:

error MSB4018: NuGet.Commands.RestoreCommandException: PackageTargetFallback and AssetTargetFallback cannot be used together. Remove PackageTargetFallback(deprecated) references from the project environment.

若要解决此问题,请删除 PackageTargetFallback (往往位于较旧的 PCL .csproj 文件) 或将其重命名为 AssetTargetFallback? 此 StackOverflow 线程还介绍了该解决方案。

我的 Xamarin 生成失败并出现错误:此项目引用此计算机上缺少 NuGet 包 (s) 。

看起来并非所有包都已还原以生成应用程序。 生成日志还将包含如下消息:

warning MSB3245: Could not resolve this reference. Could not locate the assembly "ASSEMBLY_NAME". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
error CS0246: The type or namespace name 'TYPE_OR_NAMESPACE_NAME' could not be found (are you missing a using directive or an assembly reference?)

若要解决此问题,可以将 预先生成脚本用于 appcenter-pre-build.sh 以下命令,该命令将为存储库中的每个解决方案还原所有包:

#!/bin/bash
find $APPCENTER_SOURCE_DIRECTORY -name '*.sln' -print0 | xargs -0 -n1 nuget restore -DisableParallelProcessing

我要为 Xamarin 应用程序运行单元测试

若要在 Xamarin build 中运行单元测试,请使用 生成后脚本。 例如,当基于 NUnit 的项目在名称中有 测试 时,可以使用以下脚本来生成、运行和显示结果:

echo "Found NUnit test projects:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*Test.*\.csproj' -exec echo {} \;
echo
echo "Building NUnit test projects:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*Test.*\.csproj' -exec msbuild {} \;
echo
echo "Compiled projects to run NUnit tests:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*bin.*Test.*\.dll' -exec echo {} \;
echo
echo "Running NUnit tests:"
find $APPCENTER_SOURCE_DIRECTORY -regex '.*bin.*Test.*\.dll' -exec nunit3-console {} \;
echo
echo "NUnit tests result:"
find . -name 'TestResult.xml' -exec cat {} \;

出现错误:找不到项目,但找不到 Xamarin 生成的配置

这可能是和所在的存储库深度问题 .csproj .sln 。 由于性能原因,当前分析器存在限制。

对于 .csproj 文件,它不应小于四个目录(包括存储库根目录)。

对于 .sln 文件,它不应小于两个目录(包括存储库根目录)。

如何实现还原专用 NuGet 源?

如果 NuGet.Config 文件签入到存储库中,并且位于存储库的根目录下 ,则 App Center 会在添加专用 NuGet 源时还原这些源,如以下示例中所示。 可以使用 环境变量安全地添加凭据。

对于 Mac 生成计算机:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget" value="https://api.nuget.org/v3/index.json" />
    <add key="MyGet" value="https://www.myget.org/F/MyUsername/api/v2/index.json" />
    <add key="MyAuthNuget" value="https://nuget.example.com/v2/index.json" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSourceCredentials>
    <MyAuthNuget>
      <add key="Username" value="%USER_VARIABLE%" />
      <add key="ClearTextPassword" value="%PASSWORD_VARIABLE%" />
    </MyAuthNuget>
  </packageSourceCredentials>
</configuration>

对于 Windows 生成计算机,请参阅UWP c #

如果有复杂的配置并且需要更多信息,可以参阅配置 NuGet 行为

生成停滞在 CompileToNative

如果生成遇到此 GitHub 问题中所述的类似症状,请通过添加以下参数来尝试仅生成 ARM64,如问题中所述:

<MtouchArch>ARM64</MtouchArch>

生成失败,出现错误:项目中不存在目标 "_IsProjectRestoreSupported"。

如果解决方案中有 UWP 项目,但在还原过程中,不会在旧版本的 NuGet 中以无提示方式忽略这些项目,则可能会遇到生成问题。 删除或修复解决方案中的此类 UWP 项目可以解决此问题。 再有关详细信息,请参阅此 GitHub 问题