Disable test targets just to build an IPA with xbuild / prevent them from failing

alfagemealfageme ESMember

I'm currently trying to properly set our CI configuration to build multiplatform Xamarin.Forms projects for iOS and Android. For that purpose, I divided the build stages on a pipeline. When trying to isolate the IPA build (to do it on a macOS server I have lying around the office - different than the one used for Android projects) I had an initial problem when running xbuild from the CI CLI I described in: https://stackoverflow.com/questions/44797913/use-xbuild-to-build-just-one-project-from-a-multi-project-solution

As suggested by user radical there:

You could disable the Android project from being built for your Platform=iPhone case via the Configuration manager (see Solution Configurations section).

I did so for my project from Xamarin Studio and that worked out to build the IPA for distribution flawlessly.

However, I hit another stone after including some UI & unit tests in the project. Now the beginning of my Project.sln looks like this:

Project("{[...]}") = "Project", "Project\Project\Project.csproj", "{[...]}"
EndProject
Project("{[...]}") = "Project.Droid", "Project\Project.Droid\Project.Droid.csproj", "{[...]}"
EndProject
Project("{[...]}") = "Project.iOS", "Project\Project.iOS\Project.iOS.csproj", "{[...]}"
EndProject
Project("{[...]}") = "Tests", "Tests\Tests.csproj", "{[...]}"
EndProject
Project("{[...]}") = "UITests", "UITests\UITests.csproj", "{[...]}"
EndProject

Running my old IPA-generation script: xbuild /p:Configuration="Ad-Hoc" /p:Platform="iPhone" /p:IpaPackageDir="./Builds" /t:Build Project.sln that used to succeed now returns the following error output:

/user/project/Project.sln (Build) ->
(Build target) ->
/user/project/Tests/Tests.csproj (default targets) ->
/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets (ResolveAssemblyReferences target) ->

    /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.Common.targets:  warning : Reference 'Microsoft.VisualStudio.QualityTools.UnitTestFramework' not resolved

Errors:

/user/project/Project.sln (Build) ->
(Build target) ->
/user/project/Tests/Tests.csproj (default targets) ->
/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/xbuild/14.0/bin/Microsoft.CSharp.targets (CoreCompile target) ->

    RestServiceTests.cs(1,17): error CS0234: The type or namespace name `VisualStudio' does not exist in the namespace `Microsoft'. Are you missing an assembly reference?

I'm a bit lost after looking here and there for a solution; I tried to do the same for the test stages as I did for Android (disabling it on the Configuration Manager) but tests don't appear there. Are the tests not meant to run on macOS?

Any ideas about what I'm not doing right? Or problems I might have in my project's config?

Tagged:

Answers

  • RyanDixonRyanDixon USMember ✭✭✭

    Are you able to use MSBuild as part of Visual Studio for Mac? I expect this is the more "supported" way of doing it now...
    I fire mine off from Windows, but it would be something like this I guess?

    "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /p:Configuration="Ad-Hoc" /p:Platform="iPhone" /p:ServerAddress="remotemac01" /p:ServerUser="admin" /p:ServerPassword="password" /p:OutputPath="Builds/" /t:Build Project.sln

  • alfagemealfageme ESMember

    @RyanDixon yup, I have msbuild installed on that same build machine but the error output is exactly the same regardless which tool I use :(

    Btw, I'm not using /p:ServerAddress="remotemac01" /p:ServerUser="admin" /p:ServerPassword="password" params as the CI system is directly connected to the macOS server via SSH and actually running the build script on it. Should this change something?

  • RyanDixonRyanDixon USMember ✭✭✭

    @alfageme said:
    @RyanDixon yup, I have msbuild installed on that same build machine but the error output is exactly the same regardless which tool I use :(

    Btw, I'm not using /p:ServerAddress="remotemac01" /p:ServerUser="admin" /p:ServerPassword="password" params as the CI system is directly connected to the macOS server via SSH and actually running the build script on it. Should this change something?

    Not at all, its just me being lazy when I am prototyping builds and want to set up a quick build environment! :smile:
    That error is strange though, it almost screams that something needs updating. What happens if you build from the .cspron instead of the solution?

    Sorry for the slow response.

  • alfagemealfageme ESMember

    No problem! :smile:

    msbuild /p:IpaPackageDir="./Builds" /t:Build /p:Configuration="Ad-Hoc" /p:Platform="iPhone" /p:BuildIpa=true Project.iOS.csproj:

    Build FAILED.
    
    "/Project/Project.iOS/Project.iOS.csproj" (Build target) (1) ->
    "/Project/Project/Project.csproj" (default target) (2:2) ->
    (_CheckForInvalidConfigurationAndPlatform target) ->
      /Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets(759,5): error : The OutputPath property is not set for project 'Project.csproj'.  Please check to make sure that you have specified a valid combination of Configuration and Platform for this project.  Configuration='Ad-Hoc'  Platform='iPhone'.  You may be seeing this message because you are trying to build a project without a solution file, and have specified a non-default Configuration or Platform that doesn't exist for this project. [/Project/Project/Project.csproj]
    
        0 Warning(s)
        1 Error(s)
    

    Then, removing the Configuration and Platform flags: msbuild /p:IpaPackageDir="./Builds" /t:Build /p:BuildIpa=true Project/Project.iOS/Project.iOS.csproj does not generate any errors but also does not generate any IPA artifact on the said build dir: :neutral:

    If I manually comment out the lines that corresponding to the tests:

    Project("{[...]}") = "Tests", "Tests\Tests.csproj", "{[REF]}"
    EndProject
    [...]
    #{[REF]}.Ad-Hoc|iPhone.ActiveCfg = Release|Any CPU
    #{[REF]}.Ad-Hoc|iPhone.Build.0 = Release|Any CPU
    #{[REF]}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Release|Any CPU
    #{[REF]}.Ad-Hoc|iPhoneSimulator.Build.0 = Release|Any CPU
    

    It does indeed build the IPA in the right dir. As I did point out in the first message:

    I tried to do the same for the test stages as I did for Android (disabling it on the Configuration Manager) but tests don't appear there.

    In the config manager, the option does not appear, but apparently can be applied manually like this. However I'd still like to run the tests on the macOS host if possible. Still looking for a way to do so!

Sign In or Register to comment.