AppCenter post 构建脚本 - 在执行之前尝试构建 Xamarin.UITest

AppCenter post build script - Trying to build Xamarin.UITest before executing it

我已经通过 Visual Studio App Center 为我的 iOS 和 droid xamarin 项目设置了 CI。一切都很好,直到我尝试设置我的 UI 测试 运行。我为 android 和 iOS 创建了一个 post 构建脚本,该脚本当前位于解决方案文件的文件夹下(appcenter-post-build.sh 这是必需的为了让我构建整个解决方案 [包括 Xamarin.UITest 项目])。

我在 iOS 上取得了成功,因为应用中心允许我 select 构建的解决方案,但在 Android 上不允许(appcenter-post-build.sh 与 droid.csproj) 在同一文件夹下。因此,我的解决方法是专门为 Android 创建另一个 appcenter post 脚本。我要做的是在 Android 构建之后构建 Xamarin.UITest。

每当我在 post 构建脚本上执行此操作时,我都会尝试构建 Xamarin.UITest:

/Library/Frameworks/Mono.framework/Versions/5_12_0/bin/msbuild $APPCENTER_SOURCE_DIRECTORY/MyDirectory/UITests/Project.UITests.csproj /p:Configuration=Debug

构建日志中返回此错误:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets: error : The specified iOS provisioning profile 'SampleProvisioningProfile' could not be found

它似乎也在尝试构建 iOS 项目,它应该这样做。关于这个问题的任何建议。过去一周我一直在努力让它发挥作用。

这是我用于此应用的 post-build 脚本:https://github.com/brminnick/FaceOff

对于 App Center 构建,我建议只构建特定的 .csproj 文件,因为此 post 构建脚本将构建您的 UITest 项目。

iOS Post-构建脚本

#!/usr/bin/env bash
if [ "$APPCENTER_XAMARIN_CONFIGURATION" == "Debug" ];then

    echo "Post Build Script Started"

    SolutionFile=`find "$APPCENTER_SOURCE_DIRECTORY" -name [Your Solution File].sln`
    SolutionFileFolder=`dirname $SolutionFile`

    UITestProject=`find "$APPCENTER_SOURCE_DIRECTORY" -name [Your UITest CSProj file].csproj`

    echo SolutionFile: $SolutionFile
    echo SolutionFileFolder: $SolutionFileFolder
    echo UITestProject: $UITestProject

    chmod -R 777 $SolutionFileFolder

    msbuild "$UITestProject" /property:Configuration=$APPCENTER_XAMARIN_CONFIGURATION

    UITestDLL=`find "$APPCENTER_SOURCE_DIRECTORY" -name "[Your UITest Output File Name].dll" | grep bin | head -1` 
    echo UITestDLL: $UITestDLL

    UITestBuildDir=`dirname $UITestDLL`
    echo UITestBuildDir: $UITestBuildDir

    UITestVersionNumber=`grep '[0-9]' $UITestProject | grep Xamarin.UITest|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
    echo UITestVersionNumber: $UITestVersionNumber

    TestCloudExe=`find ~/.nuget | grep test-cloud.exe | grep $UITestVersionNumber | head -1`
    echo TestCloudExe: $TestCloudExe

    TestCloudExeDirectory=`dirname $TestCloudExe`
    echo TestCloudExeDirectory: $TestCloudExeDirectory

    DSYMFile=`find "$APPCENTER_SOURCE_DIRECTORY" -name *.dsym | head -1`
    DSYMDirectory=`dirname $DSYMFile`

    npm install -g appcenter-cli@1.2.2

    appcenter login --token token

    appcenter test run uitest --app "[Your App Center App Name]" --devices "[Your App Center iOS Deivce List]" --app-path $IPAFile --test-series "master" --locale "en_US" --build-dir $UITestBuildDir --dsym-dir $DSYMDirectory --uitest-tools-dir $TestCloudExeDirectory --async
fi

Android Post-构建脚本

#!/usr/bin/env bash
if [ "$APPCENTER_XAMARIN_CONFIGURATION" == "Debug" ];then

    echo "Post Build Script Started"

    SolutionFile=`find "$APPCENTER_SOURCE_DIRECTORY" -name [Your Solution File].sln`
    SolutionFileFolder=`dirname $SolutionFile`

    UITestProject=`find "$APPCENTER_SOURCE_DIRECTORY" -name [Your UITest CSProj File].csproj`

    echo SolutionFile: $SolutionFile
    echo SolutionFileFolder: $SolutionFileFolder
    echo UITestProject: $UITestProject

    chmod -R 777 $SolutionFileFolder

    msbuild "$UITestProject" /property:Configuration=$APPCENTER_XAMARIN_CONFIGURATION

    UITestDLL=`find "$APPCENTER_SOURCE_DIRECTORY" -name "[Your UITest Output DLL].dll" | grep bin | head -1` 
    echo UITestDLL: $UITestDLL

    UITestBuildDir=`dirname $UITestDLL`
    echo UITestBuildDir: $UITestBuildDir

    UITestVersionNumber=`grep '[0-9]' $UITestProject | grep Xamarin.UITest|grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}'`
    echo UITestVersionNumber: $UITestVersionNumber

    TestCloudExe=`find ~/.nuget | grep test-cloud.exe | grep $UITestVersionNumber | head -1`
    echo TestCloudExe: $TestCloudExe

    TestCloudExeDirectory=`dirname $TestCloudExe`
    echo TestCloudExeDirectory: $TestCloudExeDirectory

    APKFile=`find "$APPCENTER_SOURCE_DIRECTORY" -name *.apk | head -1`

    npm install -g appcenter-cli@1.2.2

    appcenter login --token token

    appcenter test run uitest --app "[Your App Center App Name]" --devices "[Your Appcenter Android Device List]" --app-path $APKFile --test-series "master" --locale "en_US" --build-dir $UITestBuildDir --uitest-tools-dir $TestCloudExeDirectory --async
fi

我意识到这晚了大约 18 个月,但我只是 运行 遇到了完全相同的问题,我找到了一种方法可以让 App Center 中的东西正常运行,即使你有项目引用UI 测试项目中的平台特定项目。

  • 这只是 Android 项目中的一个问题,我们必须专门构建 UI 测试项目,以便 运行 UI 测试 Test Cloud.

@mindOfAI 原文post noted using the appcenter-post-build.sh script (further info on App Center build scripts) to build the UI test project after building the Android project to prepare 运行 UI 测试 Android。问题是,如果您想在 Visual Studio 中为 UI 测试项目设置 'Test Apps' for Mac,引用将添加到 UI 测试项目中平台特定项目。

如果 UI 测试项目引用 iOS 项目,那么它将尝试构建 iOS 项目作为 UI 测试项目的依赖项。构建 iOS 项目需要有效的 iOS 证书和配置文件,因此构建失败。

本质上,我们需要那里的引用,以便我们可以更轻松地 运行 UI 在我们的本地计算机上进行测试,但我们希望它们在 App Center 中消失,这样我们就不会浪费时间构建不必要的项目,最重要的是,这样我们在为 Android.

构建 UI 测试项目时就不需要 iOS 证书和配置文件

为了解决这个问题,在为 [= 构建 UI 测试项目之前,我使用 appcenter-pre-build.sh 脚本和 dotnet remove reference command 删除了 App Center 中的引用49=]:

伪代码

dotnet remove "Path/To/UITest/Project.csproj" reference "path/to/iOS_project.csproj" "path/to/Android_project.csproj"

示例 appcenter-pre-build.sh 用于 Android

#!/usr/bin/env bash

echo "**************************************************************************************************"
echo "**** Custom Pre Build Script -- Android Edition"
echo "**************************************************************************************************"

set -e # Exit immediately if a command exits with a non-zero status (failure)

# In order to run UI tests on local dev machines without manually installing the latest version of the app on each platform device
# you are using, the UI test project must contain references to the Android and iOS projects.
# However, in MS App Center, if the iOS reference is there for the Android build, the build will fail since there is no certificate
# nor provisioning profile to satisfy its build requirements. This next step removes the references before building for App Center
# so that we can have the best of both worlds:
echo "Removing project references to Android and iOS projects"
dotnet remove "$APPCENTER_SOURCE_DIRECTORY/MyCoolApp.UITests/MyCoolApp.UITests.csproj" reference "$APPCENTER_SOURCE_DIRECTORY/MyCoolApp.iOS/MyCoolApp.iOS.csproj" "$APPCENTER_SOURCE_DIRECTORY/MyCoolApp.Android/MyCoolApp.Android.csproj"
  • 注意:$APPCENTER_SOURCE_DIRECTORY是应用中心提供的内置环境变量。

希望这能帮助别人比我更快地找到解决方案 =)