I have a Xamarin.Forms project for Android that I can build/test/deploy/package without any errors locally and the App runs fine on my phone. Perfect!
Now I wanted to start using Azure DevOps Pipelines for CI, created a Xamarin Pipeline with the Wizard, started the Pipeline and it fails with a compilation error:
/Users/vsts/agent/2.155.1/work/1/s/MyProject/MyService.cs(41,64): error CS1503: Argument 1: cannot convert from 'char' to 'string' [/Users/vsts/agent/2.155.1/work/1/s/MyProject/MyProject.Android.csproj]
Why does it build locally but not in the Pipeline? The referenced code in the error message is the following function:
var x = string.Join(',', nextStations); // nextStations is IEnumerable<string>
I found out that the string.Join(char, IEnumerable<T>)
function is only available in the .NET Core Framework but not in other versions like .NET for Xamarin.Android 7.1 - there is only a string.Join(string, IEnumerable<T>)
function.
Of course, I could now change all of my code to not using those functions only available in .net Core. Actually I tried this, but then the Azure Build failed because one of my referenced NuGet Packages is also using such a .Net Core-only string function so that linking the application failed in the Pipeline. So this is not a solution.
So it seems that for whatever reason the Azure Pipeline tries to build my project against a different Framework. Why? Is there a way to configure this? Or is it a bug in Azure DevOps? Even when I take the msbuild command from the Pipelines log and execute it locally against my project, it runs without any errors. So why not in the pipeline?
msbuild /Users/vsts/agent/2.155.1/work/1/s/MyProject/MyProject.Android.csproj /t:PackageForAndroid /p:OutputPath=/Users/vsts/agent/2.155.1/work/1/b/Release /p:Configuration=Release
I guess this is the same problem as asked here: How to fix 'Error processing method: 'System.Void Prism.Navigation.PageNavigationService' error in Azure Pipelines But that question doesn't have a real answer (switching to Debug doesn't solve it here) and I found out more details, i.e. the different Framework versions.
So any idea how to make the Pipeline build the project?
Visual Studio 2019, Xamarin.Forms 4.2.0.778463, Android Target Framework v9.0
My azure-pipelines.yml file for reference:
trigger:
- master
pool:
vmImage: 'macos-latest'
variables:
buildConfiguration: 'Release'
outputDirectory: '$(build.binariesDirectory)/$(buildConfiguration)'
steps:
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: '**/*.sln'
- task: XamarinAndroid@1
inputs:
projectFile: '**/*droid*.csproj'
outputDirectory: '$(outputDirectory)'
configuration: '$(buildConfiguration)'