Build C#9 with AppCenter

Build C#9 with AppCenter

First I must confess something.
I think that appcenter is one of the best devops tool on the market:

But, lately, some of you may have encountered a quite upsetting issue with appcenter builds:

It cannot build C#9:

The issue lies on the mono side of appcenter, the latest stable build 6.12.0.122 cannot build C#9, it uses msbuild 15:

Trying to compile C#9 code will result numerous errors.

The good news is that the Preview (6.12.0.145) version supports C#9.

So can we uses the latest preview of mono instead of the stable one?

First you need to know that you can add custom scripts to appcenter at various build steps:

  • Post-clone (appcenter-post-clone.sh)
  • Pre-build (appcenter-pre-build.sh)
  • Post-build (appcenter-post-build.sh)

more here: https://docs.microsoft.com/en-us/appcenter/build/custom/scripts/

All you have to do is add file at the root of your project (or solution) with the correct naming convention.

Thanks to this, we can use tools to modify the environment of appcenter.
This is what Boots is doing, a great tool by the even greater Jonathan Peppers:

https://devblogs.microsoft.com/xamarin/boots-xamarin-ci/

So as stated in the article I tried to install new version of mono in the appcenter-post-clone.sh script of my build.

Unfortunately it seems to break the nuget command in some way:

https://github.com/jonathanpeppers/boots/issues/87

Then I saw the light, since it broke the nuget step, why not use Boots AFTER the restore step, in the appcenter-pre-build.sh script.

Unfortunately, I hit another issue:

https://github.com/jonathanpeppers/boots/issues/90

So should I quit?
Should I betray the Lord who is my witness and is watching from above?

Ok.
So I tried a simple custom way to install the mono preview in the pre-build script (appcenter-pre-build.sh):

#!/usr/bin/env bash

# Download Mono 6.12.0.145
wget https://download.mono-project.com/archive/6.12.0/macos-10-universal/MonoFramework-MDK-6.12.0.145.macos10.xamarin.universal.pkg

# Add execution permission
sudo chmod +x MonoFramework-MDK-6.12.0.145.macos10.xamarin.universal.pkg

# Install Mono 6.12.0.145
sudo installer -pkg MonoFramework-MDK-6.12.0.145.macos10.xamarin.universal.pkg -target /

EDIT Octobre 2021

You currently need a Post-clone script to fix a NETSDK1005 error on iOS (appcenter-post-clone.sh):

/Users/runner/hostedtoolcache/dotnet/sdk/5.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1005: Assets file '/Users/runner/work/1/s/XXXX/XXXX/obj/project.assets.json' doesn't have a target for 'netstandard2.0'. Ensure that restore has run and that you have included 'netstandard2.0' in the TargetFrameworks for your project. [/Users/runner/work/1/s/XXXX/XXXX/XXXX.csproj]

So add also a appcenter-post-clone.sh next to your iOS csproj:

#!/usr/bin/env bash

echo "Post-clone script executing..."

# Update nuget (fix NETSDK1005)
sudo nuget update -self

And guess what: