How to build Xamarin.Mac app on Azure pipelines - xamarin

Azure pipelines has tasks that support building Xamarin apps for iOS and Android. For iOS this includes the optional capability to package a .ipa file that is suitable for upload to the store.
For my project I'm building a macOS app with Xamarin.Mac and looking to be able to automate the build in Azure pipelines, but get stuck at the packaging step. Using an msbuild invocation I can have the .app built and signed in the pipeline just fine.
The next step in the VisualStudio GUI would be clicking "Build->Archive for Publishing", which produces a .xcarchive file (not entirely sure what this is? Just a zip maybe?), then you can click "Sign and Distribute" to go through a wizard that will produce the .pkg file for submission to the store.
This part is what I can't find a way to do in the pipeline. Is there a manual command line way to build the signed .pkg file in lieu of direct support for Xamarin.Mac?
EDIT: I found this article, but adding the "/p:ArchiveOnBuild=true" argument to my msbuild invocation still has not produced an xcarchive file. The docs seem to indicate that it should, so I'm at a loss there.

Old post but never the less; I have just spent most of a day struggling with the same problem.
I found this excellent blog-post helping a bunch
https://witekio.com/blog/xamarin-mac-on-azure-devops/
The idea is basically to build on MacOS and use bash instead of Powershell
I ended up with the following pipeline:
trigger:
- master
variables:
#app data
outputAppName: '<Name of outputtet app without .app>'
projectName: '<Name of your project>'
#keys and accounts
azureSubscription: <Azure subscription for publishing result>
storageAccountKey: <storage account key>
storageAccountName: <storage account name>
storageContainerName: <storage container name>
# Working Directory
workingDirectory: '$(System.DefaultWorkingDirectory)/$(projectName)'
configuration: 'Release'
outputArtifactPath: '$(workingDirectory)/$(projectName)/bin/$(configuration)/$(outputAppName).app'
# Agent VM image name
vmImageName: 'macos-latest'
stages:
- stage: Build
displayName: Build stage
jobs:
- job: Build
displayName: Build
pool:
vmImage: $(vmImageName)
steps:
- checkout: self # self represents the repo where the initial Pipelines YAML file was found
displayName: Check out
clean: true
#lfs: false # whether to download Git-LFS files
submodules: true # set to 'true' for a single level of submodules or 'recursive' to get submodules of submodules
persistCredentials: true
path: htpaa_backend_shared_util
condition:
- task: Bash#3
displayName: 'Change Mono version'
inputs:
targetType: 'inline'
script: |
SYMLINK=6_4_0
MONOPREFIX=/Library/Frameworks/Mono.framework/Versions/$SYMLINK
echo "##vso[task.setvariable variable=DYLD_FALLBACK_LIBRARY_PATH;]$MONOPREFIX/lib:/lib:/usr/lib:$DYLD_LIBRARY_FALLBACK_PATH"
echo "##vso[task.setvariable variable=PKG_CONFIG_PATH;]$MONOPREFIX/lib/pkgconfig:$MONOPREFIX/share/pkgconfig:$PKG_CONFIG_PATH"
echo "##vso[task.setvariable variable=PATH;]$MONOPREFIX/bin:$PATH"
- task: NuGetToolInstaller#1
displayName: 'Use NuGet'
- task: NuGetCommand#2
displayName: 'NuGet restore'
inputs:
restoreSolution: '$(workingDirectory)/*.sln'
- task: MSBuild#1
inputs:
solution: '$(workingDirectory)/*.sln'
platform: 'Any CPU'
configuration: '$(configuration)'
restoreNugetPackages: true
- task: ArchiveFiles#2
inputs:
rootFolderOrFile: '$(outputArtifactPath)'
includeRootFolder: true
archiveType: 'zip'
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip'
replaceExistingArchive: true
verbose: true
- task: AzureCLI#2
displayName: 'CLI Copy files to Azure Storage'
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: ps
scriptLocation: inlineScript
inlineScript: |
az storage blob upload --account-name $(storageAccountName) --container-name $(storageContainerName) --name '$(Build.BuildId)_$(projectName).zip' --file '$(Build.ArtifactStagingDirectory)/$(Build.BuildId)_$(projectName).zip' --account-name $(storageAccountName) --account-key $(storageAccountKey)

Related

Why is .NET6 self-containing app too slow?

I have app in .NET6, my deployment manager needs them as a self-contained. So, I have changed YAML build command to following:
- task: DotNetCoreCLI#2
displayName: Publish service
inputs:
command: publish
projects: <my project>.csproj
publishWebProjects: True
arguments: '--self-contained true --configuration $(BuildConfiguration) --no-restore --output "$(Build.ArtifactStagingDirectory)\service" -p:Version=$(GitVersion.FullSemVer) /p:DebugType=None /p:PublishTrimmed=true /p:PublishSingleFile=true /p:IncludeAllContentForSelfExtract=true /p:InformationalVersion=$(GitVersion.InformationalVersion)'
zipAfterPublish: false
In project file there are added new elements:
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
and appsettings.json files have added elements:
<CopyToPublishDirectory>Always</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
There is really produced a "single file" deployment (only file: Microsoft.Data.SqlClient.SNI.pdb lies next to).
But starting of the app takes ~ 30 minutes!? Reactions are 1000 times slower in comparation with non-self-contained deployment
What's wrong? How to diagnose it please?
Thanks for your answers, Petr

Unable to run xCode task in DevOps

I editted the yaml to reflect comments below.
I am getting the following error when I try to run my Pipeline and get to running the xCode task:
The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 9.0 to 14.4.99. (in target 'GoogleAppMeasurement' from project 'Pods')
My Pipeline yaml file looks like this....
variables:
scheme: "App"
sdk: "iphoneos"
configuration: "Release"
pool:
vmImage: 'macOS-10.15' #'macOS-latest'
- task: InstallAppleCertificate#2
inputs:
certSecureFile: 'Certificates.p12'
certPwd: 'mypassword'
keychain: 'temp'
deleteCert: true
- task: InstallAppleProvisioningProfile#1
inputs:
provisioningProfileLocation: 'secureFiles'
provProfileSecureFile: Distribution_Profile.mobileprovision
removeProfile: true
- script: |
sudo gem install cocoapods
displayName: 'Install Cocoa Pods'
- script: |
pod repo update
displayName: 'Update Cocoa Pods'
- script: |
ionic cordova build ios --prod --buildFlag="-UseModernBuildSystem=0"
displayName: 'Build Ionic iOS App'
- task: Xcode#5
inputs:
actions: 'build'
scheme: 'MyProject'
configuration: '$(configuration)'
sdk: '$(sdk)'
xcWorkspacePath: '$(Build.SourcesDirectory)/platforms/ios/TechPro.xcworkspace'
xcodeVersion: 'default'
packageApp: true
signingOption: manual
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)'
provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)'
teamId: 'myteamid'
exportTeamId: 'myteamid'
exportMethod: 'ad-hoc'
exportOptions: 'specify'
exportOptionsPlist: '$(Build.SourcesDirectory)/platforms/ios/MyProject/MyProject-Info.plist'
I modified the podfile to add the following...
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['CODE_SIGNING_REQUIRED'] = "NO"
config.build_settings['CODE_SIGNING_ALLOWED'] = "NO"
end
end
end
An Xcode app must be signed and provisioned to run on a device or be published to the App Store. It looks like your ios app is not successfully signed.
This arguement CODE_SIGNING_ALLOWED=No will skip the code signing. See this thread. You can also check the task log of the Xcode task to see if your app is successfully signed.
You could try to remove the arguments CODE_SIGNING_ALLOWED=No -CODE_SIGNING_REQUIRED=NO in Xcode task and check if it could work.

Azure Pipelines - Where is the CodeCoverage generated by VSTest#2?

I have tried hundreds of times but I am still unable to find that codeCoverage file generated in VSTest task.
See the following code.
I simply want to publish the Code Coverage report to the pipeline.
Help, please!
Where is that code coverage file?
Or give me some links if you don't want to waste time writing some answers.
Many thanks!
# ASP.NET
# Build and test ASP.NET projects.
# Add steps that publish symbols, save build artifacts, deploy, and more:
# https://learn.microsoft.com/azure/devops/pipelines/apps/aspnet/build-aspnet-4
trigger:
- master
jobs:
- job: devbuild
pool:
name: 'Self Hosted VS2017'
variables:
solution: '**/*.sln'
steps:
- task: NuGetToolInstaller#0
- task: NuGetCommand#2
inputs:
restoreSolution: '$(solution)'
- task: VSBuild#1
inputs:
solution: '$(solution)'
msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:Configuration=Debug /p:Platform="Any CPU" /p:OutDir=".\output\dev"'
clean: true
- task: VisualStudioTestPlatformInstaller#1
inputs:
packageFeedSelector: 'nugetOrg'
versionSelector: 'latestPreRelease'
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\dev\*.Tests.dll
searchFolder: '$(System.DefaultWorkingDirectory)'
****************************************************************************
************THIS GUY =>****************************************************
codeCoverageEnabled: true
**********************<=****************************************************
****************************************************************************
distributionBatchType: 'basedOnAssembly'
dontDistribute: false
publishRunAttachments: true
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '**/coverage.xml'
reportDirectory: '**/coveragereport'
failIfCoverageEmpty: true
This is what worked for me. I had to tell vstest to output in Cobertura format, then publish coverage results manually:
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\*Tests.dll
!**\*TestAdapter.dll
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
resultsFolder: '$(build.ArtifactStagingDirectory)/Test/Results'
otherConsoleOptions: '/collect:"Code Coverage;Format=Cobertura"' # <<<< this is the important bit
codeCoverageEnabled: True
# vv Then add publish coverage manually vv
- task: PublishCodeCoverageResults#1
inputs:
codeCoverageTool: 'Cobertura'
summaryFileLocation: '$(build.ArtifactStagingDirectory)/Test/Results/**/*.xml'
Then I got the nice HTML output in the coverage tab in DevOps
Try to add resultsFolder parameter to control file location
# Ejecucion de los Test
- task: VSTest#2
displayName: 'Ejecucion de los Test'
inputs:
testSelector: 'testAssemblies' # Options: testAssemblies, testPlan, testRun
testAssemblyVer2: | # Required when testSelector == TestAssemblies
**\*.Test.dll
searchFolder: '$(Build.SourcesDirectory)\Test'
vsTestVersion: '15.0'
platform: 'x86' # Optional
codeCoverageEnabled: true
resultsFolder: '$(build.ArtifactStagingDirectory)\Test\Results'
Set system.debug variable to true, then queue build, you can find the whole path of coverage files (search coverage in log)
By default, the coverage file's name is xx.coverage.
This is what I had to do to workaround the "nice" handling that Azure's does with the results of the vstest.
First, run vstest.console, this way azure doesn't try to publish the test results by itself and gives you control on what's going on.
Then, used a powershell to rename the *.coverage into a known file.
That's what the only way I got to have my .coverage path in order to do a decent way of exporting my coverage into the pipeline (my results are from vstest running c++ and c#, which azure doesn't handle well).
Thanks.

How to setup CI/CD for nativescript using Visual studio online/Azure dev ops tools

Im try so setup a CI/CD Pipeline for a Nativescript app, added the commands to install node and npm install but nativescript has dependencies that it need. How do I go about on Azure dev ops dynamically without having to create a vm that has nativescript and all its dependencies installed and setup
So i have used a VM and install nativescript on it and used and agent to connect to the machine and build solution, i have done the same using jenkins but jenkins was running on the vm, no i want to move the whole pipeline on azure dev ops
command used in build step: tns build android
If you don't want to use a vm you'll have to install everything needed for nativescript before building it on their hosted agent each time you create a build for your app.
A couple of important things to note. First the name of your repository is changed to 's' this messes with the naming of your entitlement file... or at least it did for me. I fix this with a bash file I add to my repository that changes the name of the path in build.xcconfig for the CODE_SIGN_ENTITLEMENTS variable. I added an npm run entitle command in my package.json file to run this before building. Second you'll want to store all files and secure passwords in the library section under pipelines in you Azure Devops project. Third, Using the classic editor is your best friend for figuring out yaml as most jobs have an option to view the YAML. You can also use the classic editor as an alternative to the YAML file
The YAML and bash file below show an example of how you can build an ipa and apk file that is stored as an artifact. You can then use that trigger a release pipeline to push the the play and app store.
# YAML File
name: Release Build
trigger:
- release/* # will start build for pull request into release branch ie. realease/version_1_0_0, release/version_2_0_0
pool:
vmImage: 'macOS-10.13'
variables:
scheme: 's' # default name/scheme created on this machine for ipa
sdk: 'iphoneos'
configuration: 'Release'
steps:
- task: NodeTool#0
inputs:
versionSpec: '10.14'
displayName: 'Install Node.js'
# Download Secure File for Android
# Note: if multiple secure files are downloaded... variable name will change and break pipeline
- task: DownloadSecureFile#1
displayName: 'download android keystore file'
inputs:
secureFile: myKeystore.keystore
#Install Apple Certificate(Distrobution)
- task: InstallAppleCertificate#2
displayName: 'Install an Apple certificate Distribution (yourcertificate.p12)'
inputs:
certSecureFile: '00000000-0000-0000-0000-000000000000' # got id from viewing file in clasic editor for pipeline
certPwd: '$(myCertificatePasswordP12)' # password stored in Library
# Install Apple Provisioning Profile(Distrobution)
- task: InstallAppleProvisioningProfile#1
displayName: 'Apple Provisioning Profile(myProvisioningProfile.mobileprovision)'
inputs:
provisioningProfileLocation: 'secureFiles' # Options: secureFiles, sourceRepository
provProfileSecureFile: '00000000-0000-0000-0000-000000000000' # Required when provisioningProfileLocation == SecureFiles
# General Set Up
- script: |
npm install -g nativescript#latest
npm install
displayName: 'Install native script and node Modules'
# variable explination
# $DOWNLOADSECUREFILE_SECUREFILEPATH is keystore file downloaded earlier
# $KEYSTORE_PASSWORD refers to the environment variable in this script which references library variable
# $(MyPlayStoreAlias) refers to library variable for your apps alias
# $BUILD_SOURCESDIRECTORY location where apk is built to
# Android
- script: |
tns build android --env.production --release --key-store-path $DOWNLOADSECUREFILE_SECUREFILEPATH --key-store-password $KEYSTORE_PASSWORD --key-store-alias $(MyPlayStoreAlias) --key-store-alias-password $KEYSTORE_PASSWORD --bundle --copy-to $BUILD_SOURCESDIRECTORY #creates apk
displayName: 'Build Android Release apk'
env:
KEYSTORE_PASSWORD: $(MyPlayStoreKeystore)
# create apk artifact
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.SourcesDirectory)/app-release.apk'
artifactName: 'apkDrop'
displayName: 'Publishing apkDrop artifact'
# have to use xcode 10.1 to meet min standards for uploading ipa... default version for this machine was lower than 10.1
#changing xcode version
- script: |
xcodebuild -version
/bin/bash -c "echo '##vso[task.setvariable variable=MD_APPLE_SDK_ROOT;]'/Applications/Xcode_10.1.app;sudo xcode-select --switch /Applications/Xcode_10.1.app/Contents/Developer"
xcodebuild -version
displayName: 'changing xcode to 10.1'
# Optional... was running into build issues with latest version
#downgrading cocoapods version
- script: |
sudo gem uninstall cocoapods
sudo gem install cocoapods -v 1.5.3
displayName: 'Using cocoapods version 1.5.3'
#iOS
- script: |
xcodebuild -version # makeing sure the correct xcode version is being used
pip install --ignore-installed six # fixes pip 6 error
npm run entitle #custom bash script used to change entitlement file
tns run ios --provision #see what provisioning profile and certificate are installed... helpful for debugging
tns build ios --env.production --release --bundle #creates xcworkspace
displayName: 'Build ios Release xcworkspace'
#build and sign ipa
- task: Xcode#5
displayName: 'Xcode sign and build'
inputs:
sdk: '$(sdk)' # custom var
scheme: '$(scheme)' # must be provided if setting manual path to xcworkspace
configuration: '$(configuration)' # custom var
xcodeVersion: 'specifyPath'
xcodeDeveloperDir: '/Applications/Xcode_10.1.app' #using xcode 10.1
xcWorkspacePath: 'platforms/ios/s.xcworkspace'
exportPath: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)' #location where ipa file will be stored
packageApp: true #create ipa
signingOption: manual
signingIdentity: '$(APPLE_CERTIFICATE_SIGNING_IDENTITY)' # distribution certificate
provisioningProfileUuid: '$(APPLE_PROV_PROFILE_UUID)' # distribution profile
#creating ipa artifact
- task: PublishBuildArtifacts#1
displayName: 'Publishing ipaDrop artifact'
inputs:
pathtoPublish: '$(agent.buildDirectory)/output/$(sdk)/$(configuration)/s.ipa'
artifactName: 'ipaDrop'
Bash file
#!/usr/bin/env bash
# filename: pipeline-entitlements.sh
echo "Editing build.xcconfig"
TARGET_KEY="CODE_SIGN_ENTITLEMENTS"
REPLACEMENT_VALUE="s\/Resources\/YOURENTITLEMENTFILENAME.entitlements"
CONFIG_FILE="./app/App_Resources/iOS/build.xcconfig"
echo "Editing $TARGET_KEY and replaceing value with $REPLACEMENT_VALUE"
sed -i.bak "s/\($TARGET_KEY *= *\).*/\1$REPLACEMENT_VALUE/" $CONFIG_FILE
echo "Finished editing build.xcconfig"

GitLab CI. Path in yml for different users

I'm trying to set up GitLab CI for .net project. Now I'm writing script in yml file. What I want to know: the path to the msbuild.exe and mstest.exe may be different for the different team members, how the same yml script may work for different users?
Or may be I'm understand how GitLab CI work in wrong way?
The path to the mstest.exe and all other referenced executable and files is based on the machine that has the GitLab runner running.
What's on your machine or anyone else's doesn't matter; Only the build server matters, so write your gitlab .yml accordingly.
Sample .net yml file
##variables:
## increase indentation carefully, one space per cascade level.
## THIS IS YAML. NEVER USE TABS.
stages:
- build
- deploy
#BUILD
# Builds all working branches
working:
stage: build
except:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
# Builds all stable/master pushes
stable:
stage: build
only:
- master
script:
- echo "Build Stage"
- echo "Restoring NuGet Packages..."
- '"c:\nuget\nuget.exe" restore "SOLUTION PATH"'
# - '"c:\nuget\nuget.exe" restore "ANOTHER ABSOLUTE PATH TO YOUR SOLUTION"'
- ''
- echo "Building Solutions..."
- C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "SOLUTION PATH"
#DEPLOY
stage: deploy
only:
- dev
script:
- echo "Deploy Stage"
#SEND TO YOUR DEV SERVER
## deploy latest master to the correct servers
stage: deploy
script:
- echo "Deploy Stage"
only:
- master
#SEND TO YOUR PRODUCTION SERVER
tags:
- .NET
#put tags here you put on your runners so you can hit the right runners when you push your code.

Resources