Build Xamarin.Mac project from terminal

1.4k Views Asked by At

I'm trying to build a Xamarin.Mac app from the terminal using mdtool.

Input:

$ Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool build -p:"Project" -t:Build -c:"Release" "../../Solution.sln"

Output:

error: The Xamarin Studio Community Edition of Xamarin.Mac does not support building outside of Xamarin Studio. Please go to https://store.xamarin.com to upgrade to the Business Edition.

I thought it is free now because of the Microsoft acquisition. There is also no Business Edition available anymore AFAIK.

Is there still a way to build from the terminal? I'm using the latest Xamarin version.

2

There are 2 best solutions below

0
On

If you are building a Xamarn.Mac Unified-based project, you can use xbuild:

Debug:

xbuild CLIBuild.csproj /target:Build /p:Configuration=Debug

Release:

xbuild CLIBuild.csproj /target:Build /p:Configuration=Release

Note: For a "Release" build make sure that your Apple OS-X code signing keys are installed in the keychain

Note: The "new" x-plat OS-X msbuild (14.1.0.0) does not work quite yet. It fails on including certain references. I do not know if it is a msbuild issue or a problem in one of the Xamarin.Mac .targets files

If you are building a Xamarin.Mac Classic-based project, the following should work:

/Applications/Xamarin\ Studio.app/Contents/MacOS/mdtool build CLIBuild.csproj

Note: I just tested this and it still makes a request to "activation.xamarin.com" for some reason but builds properly for me on the Community Edition. I do not normally develop Classic-API based apps anymore thus to not build via mdtool very much).

I would report this issue @ https://bugzilla.xamarin.com

0
On

Update October 2022: For Visual Studio for Mac 2022, The msbuild command is the recommended and supported replacement for vstool, which had replaced mdtool.

msbuild -target:Build "my.sln" -property:Configuration="Debug" -property:Platform="iPhone" 

Original answer Note that now in Visual Studio 2017 for Mac mdtool is replaced by vstool under the /Applications/Visual Studio.app folder.

My build line looks like this:

/Applications/Visual\ Studio.app/Contents/MacOS/vstool --verbose build --f --target:Build --configuration:"Debug|iPhone" --buildfile:my.sln > $BuildResults

See also: mdtool creates IPA file when using release but not when using debug configuration

Update January 2019, I have found very little guidance on the web about what exactly vstool can do and how to use it. I believe it to be the Microsoft version of the mdtool, which is part of the Monodevelop project at Github (mono/monodevelop). The mdtool source code is under monodevelop/main/src/tools folder. It appears to be a runner for a variety of tools available in the Monodevelop / Visual Studio installation.

Running

/Applications/Visual\ Studio.app/Contents/MacOS/vstool -q 

will list out the available tools.

There is also a man page as part of the Monodevelop build process, at monodevelop/main/man which provides a bit more enlightenment. I was shown how to use the specific command by someone who was very familiar with the project.