我有一个引用Core PCL(Profile111)的Xamarin.Android项目。 Core PCL引用Microsoft.WindowsAzure.Mobile和Microsoft.WindowsAzure.Mobile.SQLLiteStore(见下文):
<Reference Include="Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.Mobile.Client.3.1.0\lib\portable-win+net45+wp8+wpa81+monotouch+monoandroid\Microsoft.WindowsAzure.Mobile.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.WindowsAzure.Mobile.SQLiteStore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.Mobile.Client.SQLiteStore.3.1.0\lib\portable-win+net45+wp8+wpa81+monotouch10+monoandroid10+xamarinios10\Microsoft.WindowsAzure.Mobile.SQLiteStore.dll</HintPath>
<Private>True</Private>
</Reference>
除了这些(作为NuGet包添加,我引用ReactiveUI和Microsoft.Bcl。请参阅packages.config以获取引用包的完整列表:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Azure.Mobile.Client" version="3.1.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Azure.Mobile.Client.SQLiteStore" version="3.1.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl" version="1.1.10" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="portable45-net45+win8+wpa81" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="portable45-net45+win8+wpa81" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="portable45-net45+win8+wpa81" />
<package id="reactiveui" version="7.0.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="reactiveui-core" version="7.0.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="Rx-Core" version="2.2.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Rx-Interfaces" version="2.2.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Rx-Linq" version="2.2.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Rx-Main" version="2.2.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Rx-PlatformServices" version="2.2.5" targetFramework="portable45-net45+win8+wpa81" />
<package id="Splat" version="1.4.0" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.2" targetFramework="portable45-net45+win8+wpa81" />
<package id="SQLitePCLRaw.core" version="1.1.2" targetFramework="portable45-net45+win8+wpa81" />
</packages>
我在VSTS中遇到编译问题,但在我的框中没有本地编译问题。在我的盒子上,我可以在Debug或Release配置中正常编译。在VSTS上,我收到以下警告/错误:
No package sources were found in the NuGet.config file at C:\a\1\s\development\.nuget\NuGet.config
setup.txt (0, 0)
setup.txt(0,0): Warning XA0101: @(Content) build action is not supported
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets (1820, 5)
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): Warning MSB3243: No way to resolve conflict between "Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "Microsoft.WindowsAzure.Mobile, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Choosing "Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets (1820, 5)
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): Warning MSB3243: No way to resolve conflict between "Microsoft.WindowsAzure.Mobile.SQLiteStore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" and "Microsoft.WindowsAzure.Mobile.SQLiteStore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35". Choosing "Microsoft.WindowsAzure.Mobile.SQLiteStore, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" arbitrarily.
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets (1820, 5)
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1820,5): Warning MSB3247: Found conflicts between different versions of the same dependent assembly. In Visual Studio, double-click this warning (or select it and press Enter) to fix the conflicts; otherwise, add the following binding redirects to the "runtime" node in the application configuration file: <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Microsoft.WindowsAzure.Mobile.SQLiteStore" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" /></dependentAssembly></assemblyBinding><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"><dependentAssembly><assemblyIdentity name="Microsoft.WindowsAzure.Mobile" culture="neutral" publicKeyToken="31bf3856ad364e35" /><bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" /></dependentAssembly></assemblyBinding>
development\ShoppingList.Mobile.Core\Services\ShoppingListService.cs (15, 17)
development\ShoppingList.Mobile.Core\Services\ShoppingListService.cs(15,17): Error CS0433: The type 'MobileServiceClient' exists in both 'Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.WindowsAzure.Mobile, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
development\ShoppingList.Mobile.Core\Services\ShoppingListService.cs (16, 17)
development\ShoppingList.Mobile.Core\Services\ShoppingListService.cs(16,17): Error CS0433: The type 'IMobileServiceSyncTable<T>' exists in both 'Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'Microsoft.WindowsAzure.Mobile, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
Process 'msbuild.exe' exited with code '1'.
在VSTS上构建时,我不知道它在哪里引用了3.0.0.0版本。请帮助和谢谢。
更新 为了隔离问题的来源,我向Microsoft.WindowsAzure.Mobile和Microsoft.WindowsAzure.Mobile.SQLLiteStore引用添加了引用别名,如下所示:
<Reference Include="Microsoft.WindowsAzure.Mobile, Version=3.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Azure.Mobile.Client.3.1.0\lib\portable-win+net45+wp8+wpa81+monotouch+monoandroid\Microsoft.WindowsAzure.Mobile.dll</HintPath>
<Private>True</Private>
<Aliases>core</Aliases>
</Reference>
并在代码中:
extern alias core;
using core.Microsoft.WindowsAzure.MobileServices;
using core.Microsoft.WindowsAzure.MobileServices.SQLiteStore;
using core.Microsoft.WindowsAzure.MobileServices.Sync;
此举消除了上述错误,但又出现了一个新错误:
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets (1404, 2)
C:\Program Files (x86)\MSBuild\Xamarin\Android\Xamarin.Android.Common.targets(1404,2): Error : Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'Newtonsoft.Json.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve(AssemblyNameReference reference, ReaderParameters parameters)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences(ICollection`1 assemblies, AssemblyDefinition assembly, Boolean topLevel)
at Xamarin.Android.Tasks.ResolveAssemblies.Execute()
在我看来,包恢复可能无法正常使用此NuGet。将尝试按照本文中的步骤查看是否可以更正程序包还原:https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore#msbuild-integrated-restore。