Forum Xamarin.iOS

Run Pre-Build Event on Paired Mac

Is there a good way to run a pre-build event on the paired mac instead of the local windows machine?

I have a simple c library that I would like to compile and dynamically link to in my xamarin.ios project. I was hoping I could just include the files in a folder in the visual studio project and run the makefile to build the library as part of a pre-build step.


  • geolocategeolocate Member ✭✭

    Obviously I could run ssh commands which would require separate setup. It would be nice to reuse the xma connection though. Is there any documentation on using the xma interface? Can it be used to run shell commands?

    After some more digging it looks like I could setup a second project and leverage the linux dev workload. Looking at the basic requirements it "should" work to build the dylib on the Mac, unless I'm missing something. Has anyone done this with a Mac in conjunction with a xamarin.ios project?

  • geolocategeolocate Member ✭✭

    In case anyone runs in to this question in the future... I ended up building the c library with a second linux workload dev studio project and then referencing that library from my Xamarin iOS project. To make it work I switched to a static library.

    Couple things to watch out for;

    • The linux workload project uses modified date for file copy to the Mac. So you will want to touch the file dates if you are moving file locations around when setting up the project structure initially.

    • The static library file name needs to start with "lib" for the linker to find it.

    • The documentation says to add the gcc_flags to the project iOS Build properties. It is easier to just use the Add Native Reference context menu instead as the library file gets copied correctly to the Mac and the linker can find it.

    • The dll import attribute should be passed __Internal to find the statically linked function:
      [DllImport("__Internal", EntryPoint = "testbar")]
      public static extern int TestBar();

Sign In or Register to comment.