4
votes

​I am trying to use Team Services CI Build, but it keeps on failing with the same error:

##[error]MobileClient\LoginNavigation\CommentPage.xaml.cs(1,7): Error CS0246: The type or namespace name 'Android' could not be found (are you missing a using directive or an assembly reference?)

Which seems to be right, since in a previous step it is complaining about not finding that library:

##[warning]C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Mono.Android". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

Also, it is logged where the build is searching it:

For SearchPath "{HintPathFromItem}".
Considered "..\..\..\..\..\..\..\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v6.0\Mono.Android.dll", but it d  idn't exist.For SearchPath "{TargetFrameworkDirectory}".
For SearchPath "{TargetFrameworkDirectory}".
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.winmd", but  it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.dll", but it didn't exist.
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile259\Mono.Android.exe", but it didn't exist.
For SearchPath "{RawFileName}".
Considered treating "Mono.Android" as a file name, but it didn't exist.

To my understanding, this file is missing in the Team Services build server, right? How could I solve this? Should it be necessary to change this directory?

One important thing is that locally, in my machine, the Visual Studio and the command line MSBuild are working correctly.

This happens during the Visual Studio Build step, which has the following configuration:

  • MSBuild Configuration: MSBuild ​x86
  • Visual Studio Version: Visual Studio 2015
  • MSBuild Arguments: /p:DeployOnBuild=true /p:WebPublishMethod=Package
  • /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true
  • /p:PackageLocation="$(build.artifactstagingdirectory)\"
  • Visual Studio Build Solution step version: 1.*

Here are the steps of the Team Services build:enter image description here

​​

1
Can you reproduce this issue with a simple project? You can share it on the OneDrivestarian chen-MSFT
Given you have what looks to be a Xamarin solution I would not recommend using those publish arguments. Have you tried using are Xamarin Android template?Chris Patterson
What's the path of Mono.Android reference? (Right click Mono.Android reference> Properties)starian chen-MSFT
Are you trying to build a Xamarin Android project? If yes, try using "Xamarin.Android" template when you create the build definition.Eddie Chen - MSFT

1 Answers

1
votes

Ok so after reading the answers and suggestions I received, I got a hint of what I had to do to resolve this. Basically, I was making two mistakes:

First of all, on the project that was failing, I changed the Mono.Android reference to one inside the project's folder. Even though that error disappeared, I kept on having more and more errors related to Xamarin and Android.

So that's when I followed another suggestion in this thread: using a Xamarin.Android template. The thing is, that in this project I have a .sln file, which contains different type of projects, including a Xamarin project, a Web Api, and some Class Libraries. I was trying to build them all in the same Team Services build definition, but I realized it was much more efficient to have different definitions according to the different type of projects.

In consequence, I ended up having a build definition for the Xamarin project, using the Xamarin.Android template, and another one for a .sln file I created with all the projects used by the Web Api project. The amount of errors was reduced drastically, and I felt I wasn't "swimming against the tide" anymore.

I would suggest everyone having a solution with a wide variety of project types to do the same.