I'm trying to build a Xamarin iOS app in Visual Studio App Center. The solution contains two projects. One is a Xamarin iOS project. The other is a bindings library project. The bindings library project is configured with the Allow 'unsafe' code option.

But the Xamarin.iOS build task in the App Center fails saying:
Unsafe code may only appear if compiling with /unsafe

I'm able to build the solution locally without any issues.
Anybody an idea?
After trying different things I switched from the .csproj file to the .sln file in the build configuration.

Can somebody verify this?
Probably you encounter the error like this when building in App Center:
error CS0227: Unsafe code may only appear if compiling with /unsafe
Please try either building from .sln so that your PCL configuration will be honored or add Release|iPhone (or the one you're trying to build) configuration with unsafe enabled to the PCL/.NET Standard project.
Reason: when building from .csproj file, msbuild expects to have the same configuration names in all referenced projects, cause there is no possibility to know how to map iOS project configuration Release|iPhone to configurations in PCL project which normally do not have *|iPhone part in it.
Documentation reference - https://learn.microsoft.com/en-us/appcenter/build/xamarin/ios/#312-building-from-the-project-file-csprojfsproj
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With