我已经通过Visual Studio App Center为我的iOS和droid xamarin项目设置了CI。直到我尝试设置UI测试运行为止,一切都很好。我为android和iOS创建了一个后构建脚本,该脚本当前位于解决方案文件的文件夹下(appcenter-post-build.sh,这是我构建整个解决方案[包括Xamarin.UITest项目]所必需的)。
我在iOS上取得了成功,因为应用中心允许我选择构建解决方案,但是在Android上则不允许(与droid.csproj位于同一文件夹下的appcenter-post-build.sh) 。因此,我的解决方法是为Android创建另一个appcenter发布脚本。我想做的是在Android构建之后构建Xamarin.UITest。
每当我在构建脚本时执行此操作时,都会尝试构建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项目。有关此问题的任何建议。在过去的一周里,我一直在努力使它工作。
答案 0 :(得分:2)
这是我为此应用程序使用的构建后脚本:https://github.com/brminnick/FaceOff
对于App Center构建,我建议仅构建特定的.csproj
文件,因为此后构建脚本将构建您的UITest项目。
#!/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`
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\}\.[0-9]\{1,10\}\-'dev`
echo UITestPrereleaseVersionNumber: $UITestVersionNumber
UITestVersionNumberSize=${#UITestVersionNumber}
echo UITestVersionNumberSize: $UITestVersionNumberSize
if [ $UITestVersionNumberSize == 0 ]
then
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
fi
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
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
#!/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`
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\}\.[0-9]\{1,10\}\-'dev`
echo UITestPrereleaseVersionNumber: $UITestVersionNumber
UITestVersionNumberSize=${#UITestVersionNumber}
echo UITestVersionNumberSize: $UITestVersionNumberSize
if [ $UITestVersionNumberSize == 0 ]
then
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
fi
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
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
答案 1 :(得分:2)
我意识到这要晚18个月了,但我遇到了完全相同的问题,即使在UI中有对平台特定项目的项目引用,我也找到了一种使App Center正常运行的方法。测试项目。
@mindOfAI的原始帖子在构建Android项目以准备运行Android的UI测试之后,使用appcenter-post-build.sh
脚本(further info on App Center build scripts)来构建UI测试项目。问题是,如果要在Visual Studio for Mac中为UI测试项目设置“测试应用程序”,则会将引用添加到平台特定项目的UI测试项目中。
如果UI测试项目引用了iOS项目,则它将尝试将iOS项目构建为UI测试项目的依赖项。构建iOS项目需要有效的iOS证书和配置文件,因此构建失败。
从本质上讲,我们希望在那里有引用,以便我们可以更轻松地在本地计算机上运行UI测试,但我们希望它们在App Center中消失,这样我们就不会浪费时间来构建不必要的项目,最重要的是,我们赢了构建适用于Android的UI测试项目时,不需要iOS证书和配置文件。
为解决此问题,在构建Android的UI测试项目之前,我使用了appcenter-pre-build.sh
脚本和dotnet remove reference
command在App Center中删除了引用:
dotnet remove "Path/To/UITest/Project.csproj" reference "path/to/iOS_project.csproj" "path/to/Android_project.csproj"
#!/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
是应用中心提供的内置环境变量。希望这可以帮助某人比我快得多的解决方案=)