Visual Studio 更新 (16.8.1) 导致 CI 构建失败

Visual Studio update (16.8.1) lead to CI build failures

我们最近将构建服务器更新为使用 Visual Studio 16.8.1 和 Xamarin.iOS 14.4.1.3,并且之前使用 运行 的 MSBuild 命令遇到了问题。

郑重声明,我们正在构建 Xamarin Forms 解决方案并在此处定位 iOS。

命令是:

"C:\Program Files (x86)\Microsoft Visual Studio19\Professional\MSBuild\Current\Bin\msbuild" MySolution.sln /p:Configuration="AppStore" /p:Platform="iPhone" /p:ServerAddress="" /p:ServerUser=""

我已经尝试搜索它正在报告的特定错误消息(如下),但是到目前为止我还没有找到任何有用的信息。

C:\Program Files (x86)\Microsoft Visual Studio19\Professional\MSBuild\Xamarin\iOS\Xamarin.Shared.targets(230,3): error MSB4044: The "GetMinimumOSVersion" task was not given a value for the required parameter "SdkVersion".

更新

经过进一步挖掘,我相信我已经将错误的根源追溯到 Xamarin.Shared.props.

中未设置的这些行
<!-- SdkVersion -->
<_SdkVersion Condition="'$(_PlatformName)' == 'macOS'">$(MacOSXSdkVersion)</_SdkVersion>
<_SdkVersion Condition="'$(_PlatformName)' != 'macOS'">$(MtouchSdkVersion)</_SdkVersion>

我一直没能找出是什么设置了 MtouchSdkVersion 以及为什么它没有被设置。上面引用部分正上方的评论指出:

Sometimes we've used different variable names for the same thing for Xamarin.iOS and Xamarin.Mac projects. Here we try to unify those variables

会不会是这种统一改变了一些曾经有效的行为?

这当然不是问题的永久解决方案,但 Xamarin 团队提供了解决方法。作为参考,回复在 GitHub

we're investigating it, but it looks like the build process is getting disconnected after running the clean targets, so if you run Build instead of Rebuild you shouldn't face this.

In the meantime, a potential workaround to unblock Rebuilds would be to edit <VS Install path>\MSBuild\Xamarin\iOS\Xamarin.iOS.Windows.After.targets and remove the _SayGoodbye entry from the CleanDependsOn property group.

我可以确认这让我们的 CI 构建再次运行。

不言而喻,但我想说清楚,您应该在执行此操作之前备份 Xamarin.iOS.Windows.After.targets 文件的副本。

这在 Visual Studio 2019 版本 16.8.3 中再次抬头。看起来他们已经将问题转移到: <VS Install path>\MSBuild\Xamarin\iOS\Xamarin.Messaging.targets 通过删除第 52 行对 _DisconnectAfterClean 目标的 _SayGoodbye 依赖,我能够再次获得我的构建 运行。

<Target Name="_DisconnectAfterClean" Condition="'$(IsRebuild)' != 'true'" DependsOnTargets="" />