Use xbuild to build just one project from a multi-project solution

763 views Asked by At

First of all, I'm a complete beginner on the whole Xamarin-life-cycle, build tools and terms, so sorry if this is quite basic/incorrect in some wording.

We have a Example.sln file with the following project definitions; one for Android and one for iOS:

Project("{...}") = "Example", "Example\Example\Example.csproj", "{...}"
EndProject
Project("{...}") = "Example.Droid", "Example\Example.Droid\Example.Droid.csproj", "{...}"
EndProject
Project("{...}") = "Example.iOS", "Example\Example.iOS\Example.iOS.csproj", "{...}"
EndProject

I'm currently trying to build just the iOS project with xbuild on the command line. My question is if there's a way to specify this on an xbuild flag; e.g. tried with /t:Example.ios:Build and stuff alike without luck. So I simply tried unbundling the Android project and running:

$ xbuild /p:Configuration="Ad-Hoc" \ 
/p:Platform="iPhone" \ 
/p:IpaPackageDir="./Builds" \ 
/t:Build Example.sln

Which, I guess, since the Droid project is still before iOS on the .sln, is failing when looking for the Android SDK:

/Users/ci/Example-app/Example.sln (Build) ->
(Build target) ->
/Users/ci/Example-app/Example/Example.Droid/Example.Droid.csproj (default targets) ->
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets (_BuildSdkCache target) ->

    : error XA5205: The Android SDK Directory could not be found. Please set via /p:AndroidSdkDirectory.

Temporarily removing the Android project from the solution did the trick (preserving the Example\Example.Droid files but commenting out the 2 lines) but it's not quite optimal for me, i.e. maybe in some other CI job I want to just build the Android app, etc.

Thanks!

2

There are 2 answers

0
Hichame Yessou On

I would suggest you to execute the xbuild command from the folder of your Xamarin iOS project or specify a target for your command like this:

xbuild /p:..... iOSProject/app.csproj

xbuild takes the path of the project or solution file to build, as the main argument. If no file is specified then it tries to build any solution file or project file in the current directory, that has a *proj extension.

If you need to force an SDK or a specific build tools path you have to specify:

/p:AndroidSdkDirectory=$YOUR_SDK_PATH
/p:AndroidSdkBuildToolsVersion=23.x.x

xbuild command reference

0
radical On

You could disable the Android project from being built for your Platform=iPhone case via the Configuration manager (see Solution Configurations section). Or you can create a separate config/platform combo for your solution that enables only the common projects and the iOS ones.

Once you have that, then you can just select that configuration and platform combination on the command line with xbuild or msbuild with xbuild /p:Configuration=.. /p:Platform=.. foo.sln.