microsoft/appcenter

Image for xamarin ios 16.4: unable to restore solution if it contains a Xamarin.Android project

softlion opened this issue · 8 comments

Describe the solution you'd like
Image 16.4 (xamarin ios) does not have this issue.
Image 16.2 does not have this issue.

[command]/bin/bash -c /usr/bin/find . -name '*.sln' -type f -print0 | /usr/bin/xargs -0 grep -l 'xxxxx.iOS.csproj' | /usr/bin/xargs -I '{}' nuget restore '{}' -DisableParallelProcessing
MSBuild auto-detection: using msbuild version '15.0' from '/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/15.0/bin'.
/Users/runner/work/1/s/xxxxx/xxxxx.Droid/xxxxx.Droid.csproj(150,13): error MSB4226: The imported project "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/xbuild/Xamarin/Android/Xamarin.Android.CSharp.targets" was not found. Also, tried to find "Xamarin/Android/Xamarin.Android.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "/Library/Frameworks/Mono.framework/External/xbuild/" . These search paths are defined in "/Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/MSBuild.dll.config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.
/var/folders/lf/qycgv4fd6yjcj__vqnk_wxhm0000gn/T/NuGetScratch/py8ev7ym.9vl.nugetrestore.targets(382,5): warning MSB4181: The "MSBuild" task returned false but did not log an error. [/var/folders/lf/qycgv4fd6yjcj__vqnk_wxhm0000gn/T/NuGetScratch/z6gs83uf.j7i.nugetinputs.targets]
/var/folders/lf/qycgv4fd6yjcj__vqnk_wxhm0000gn/T/NuGetScratch/py8ev7ym.9vl.nugetrestore.targets(394,5): warning : Skipping restore for project '/Users/runner/work/1/s/xxxxx/xxxxx.Droid/xxxxx.Droid.csproj'. The project file may be invalid or missing targets required for restore. [/var/folders/lf/qycgv4fd6yjcj__vqnk_wxhm0000gn/T/NuGetScratch/z6gs83uf.j7i.nugetinputs.targets]

##[error]/bin/bash failed with return code: 1
##[error]/bin/bash failed with error: /bin/bash failed with return code: 1

Describe alternatives you've considered
Rollback to 16.2

brunck commented

This is incredibly painful. The best solution is to have a post-clone step that removes the Android projects from the solution at runtime, then the NuGet restore step of the entire solution will work. There's a pretty cool command called dotnet sln that will do this. I'd suggest looking into that.

Note that trying to run NuGet restore just for certain projects is inadvisable, because project dependencies don't get resolved such that it will restore the projects in the right order. You really have to NuGet restore at the solution level.

This week new issue. My customer's project does not compile anymore, with 16.4 oe 16.2, maybe because Visual Studio Mac has been removed from the images.

I switched to Azure pipelines to build the IPAs, and published them to Appcenter Distribute.
If someone is interested I can publish the yaml pipeline here. It took me 2 days to create successfully.
This is time lost before migrating to maui and codemagic.

brunck commented

Yes, the problem stems from Xamain.iOS and Xamarin.Android not being on the macOS-13 images that are used by AppCenter for Xamarin iOS builds (via Azure DevOps). Setting the mono version back to an earlier version in an AppCenter build configuration gets around that, but causes other problems because it uses Xcode 14.2 rather than 15.x.

Just in case it helps anyone I was having the same issue and followed @brunck advice of using dotnet sln and got it to work.
I created an appcenter-post-clone.sh script file in the iOS project folder like the documentation specifies.
Inside it added the line below:
dotnet sln <path to solution> remove <path to android project>

@softlion

Hi,
I also have some problems with AppCenter since some weeks, so I would be very interested in the Azure Pipelines scripts. Can you provide them to me?

Thanks

Just in case it helps anyone I was having the same issue and followed @brunck advice of using dotnet sln and got it to work. I created an appcenter-post-clone.sh script file in the iOS project folder like the documentation specifies. Inside it added the line below: dotnet sln <path to solution> remove <path to android project>

@dinisvieira Can you help me please with a complete sample of your appcenter-post-clone.sh

I do this script ans i have an error -> Could not find solution or directory /Users/runner/work/1/s/project/project.sln.
For an other script (appcenter-pre-build.sh) i use variable like SLN_FILE or ANDROID_PROD_FILE to find files in project and this is ok no error

My script
#!/usr/bin/env bash

SLN_FILE=$APPCENTER_SOURCE_DIRECTORY/project/project.sln
ANDROID_CSPROJ_FILE=$APPCENTER_SOURCE_DIRECTORY/project/project.Android/project.Android.csproj

dotnet sln $SLN_FILE remove $ANDROID_CSPROJ_FILE

If i add in the script an echo $SLN_FILE; -> i have in the build -> /Users/runner/work/1/s/project/project.sln

Just in case it helps anyone I was having the same issue and followed @brunck advice of using dotnet sln and got it to work. I created an appcenter-post-clone.sh script file in the iOS project folder like the documentation specifies. Inside it added the line below: dotnet sln <path to solution> remove <path to android project>

@dinisvieira Can you help me please with a complete sample of your appcenter-post-clone.sh

I do this script ans i have an error -> Could not find solution or directory /Users/runner/work/1/s/project/project.sln. For an other script (appcenter-pre-build.sh) i use variable like SLN_FILE or ANDROID_PROD_FILE to find files in project and this is ok no error

My script #!/usr/bin/env bash

SLN_FILE=$APPCENTER_SOURCE_DIRECTORY/project/project.sln ANDROID_CSPROJ_FILE=$APPCENTER_SOURCE_DIRECTORY/project/project.Android/project.Android.csproj

dotnet sln $SLN_FILE remove $ANDROID_CSPROJ_FILE

If i add in the script an echo $SLN_FILE; -> i have in the build -> /Users/runner/work/1/s/project/project.sln

It's not easy for me to help you without knowing your solution/folder structure.
But the trick I used was taking into account that the "current directory" is going to be the place where you have the csproj that is being built.
From there I "go back/up" into other folders.

For my scenario I'm running for the iOS project so I "go back/up" to the Solution and Android projects. (each ../ goes back/up one folder)
dotnet sln ../../../SolutionName.sln remove ../Android/AndroidProject.csproj