VSTS CI构建Xamarin.Forms项目时无法找到MVVMLight程序集
I see you're hitting a frustrating snag where your VSTS CI build reports successful NuGet restores for packages like MvvmLight and CommonServiceLocator, but then fails to resolve those references during the Xamarin.Android build. Let's break down what's going on and how to fix it.
What the Logs Reveal
First, looking at your NuGet restore log, the process is definitely pulling down the correct packages:
2018-05-14T09:57:17.0372995Z Installing WebP.Touch 1.0.8. 2018-05-14T09:57:17.0373097Z Lock not required - Package already installed Xamarin.Forms 3.0.0.446417 2018-05-14T09:57:17.0373227Z Acquiring lock for the installation of MvvmLight 5.4.1 2018-05-14T09:57:17.0373328Z Acquired lock for the installation of MvvmLight 5.4.1 2018-05-14T09:57:17.0373530Z Installing MvvmLight 5.4.1. 2018-05-14T09:57:17.0373650Z Acquiring lock for the installation of Newtonsoft.Json 11.0.2 2018-05-14T09:57:17.0373759Z Lock not required - Package already installed Newtonsoft.Json 11.0.2 2018-05-14T09:57:17.0373876Z Acquiring lock for the installation of AiForms.Effects 1.3.0 2018-05-14T09:57:17.0373985Z Lock not required - Package already installed AiForms.Effects 1.3.0 2018-05-14T09:57:17.0374117Z Acquiring lock for the installation of CommonServiceLocator 2.0.2
But during the build, MSBuild is looking in completely wrong locations:
2018-05-14T09:57:57.6046899Z For SearchPath "{HintPathFromItem}". 2018-05-14T09:57:57.6047274Z Considered "..\..\..\..\..\.nuget\packages\mvvmlightlibs\5.4.1\lib\xamarin.ios10\GalaSoft.MvvmLight.dll", but it didn't exist.
It's checking the xamarin.ios10 folder for MvvmLight—total mismatch for an Android project. Similarly, the CommonServiceLocator hint path points to a relative location that doesn't exist on the build agent.
Fixes to Try
Here are the most likely solutions to resolve this:
Correct HintPaths in your .csproj: Open your Android project's .csproj file and check the
<Reference>entries for these packages. Ensure theHintPathpoints to the correct framework folder for Xamarin.Android (e.g.,..\packages\mvvmlightlibs\5.4.1\lib\netstandard2.0\GalaSoft.MvvmLight.dllor the appropriate monoandroid folder). Remove any references to iOS-specific paths.Migrate to PackageReference: If your project still uses
packages.config, switch to PackageReference (right-click the project > Manage NuGet Packages > Settings > Default package management format). This eliminates manual hint path issues, as it automatically resolves the correct assembly paths based on your target framework.Clean NuGet cache on the build agent: Add a step in your VSTS pipeline before the NuGet restore to clear the cache. Run this command:
nuget locals all -clearThis ensures the build agent pulls fresh package copies instead of using potentially corrupted cached versions.
Verify NuGet restore step configuration: In VSTS, make sure your NuGet restore step uses a recent version of NuGet (v4.7+ is recommended for .NET Standard support) and is set to restore packages for all target frameworks in your solution.
Check your project's target framework: Ensure your Xamarin.Android project targets a framework compatible with your packages. For MvvmLight 5.4.1, netstandard2.0 or monoandroid8.0+ should work. If your target is too old, the package might not have the required assembly for it.
Give these steps a shot, and you should see those reference errors vanish in your CI build.
内容的提问来源于stack exchange,提问作者King Chan

