Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build fails in Visual Studio App Center for Xamarin iOS: Unsafe code may only appear if compiling with /unsafe

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.

enter image description here

But the Xamarin.iOS build task in the App Center fails saying:

Unsafe code may only appear if compiling with /unsafe

enter image description here

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.

enter image description here

Can somebody verify this?

like image 757
Luca Avatar asked Feb 03 '18 12:02

Luca


1 Answers

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

like image 63
nevalenny Avatar answered Oct 11 '22 13:10

nevalenny