From c0f754cab66984021df4112b48524b710bd0b689 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 20 Apr 2017 13:28:13 +0100 Subject: [PATCH] [Xamarin.Android.Build.Tests] Switch over to use the latest Nuget. We are starting to see Nuget packages only be available from the v3 repositories. Our tests are using Nuget.Core v2. But Nuget v3 does not have the same API as v2 if you want to manually restore packages. In fact the api is "unstable" and it not simple to use. What was a couple of lines of code now has to be a mess of subclasses and other support files. The Nuget for those have also exploded into a mass of 24+ packages. So easiest solution is to download the latest nuget.exe client from nuget.org. This means it is (or should be) up to date and will work with both v2 and v3. Rather than calling the API manually for the unit tests we just shell out to restore the packages. --- .../xa-prep-tasks/xa-prep-tasks.targets | 19 ++++++++++++++++--- .../Common/XamarinProject.cs | 15 +++++++-------- .../Xamarin.ProjectTools.csproj | 9 +++++---- .../Xamarin.ProjectTools/packages.config | 5 ++--- 4 files changed, 30 insertions(+), 18 deletions(-) diff --git a/build-tools/xa-prep-tasks/xa-prep-tasks.targets b/build-tools/xa-prep-tasks/xa-prep-tasks.targets index 68a02d07b8d..b4d1c51058a 100644 --- a/build-tools/xa-prep-tasks/xa-prep-tasks.targets +++ b/build-tools/xa-prep-tasks/xa-prep-tasks.targets @@ -1,4 +1,4 @@ - + @@ -6,6 +6,8 @@ <_AzureBaseUri>https://xamjenkinsartifact.blob.core.windows.net/xamarin-android/xamarin-android/bin/ + <_NuGetUri>https://dist.nuget.org/win-x86-commandline/latest/nuget.exe + <_NuGetPath>$(MSBuildThisFileDirectory)\..\..\.nuget + + + + + DependsOnTargets="_GetBundleOutputPath;_DownloadBundle;_ExtractBundle;_DownloadNuGet"> - \ No newline at end of file + diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs index 7cef368123f..37f84a9d63e 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -6,7 +6,6 @@ using Microsoft.Build.Construction; using System.Diagnostics; using System.Text; -using NuGet; namespace Xamarin.ProjectTools { @@ -380,12 +379,12 @@ public void NuGetRestore (string directory, string packagesDirectory = null) if (!Packages.Any ()) return; - IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository ("https://packages.nuget.org/api/v2"); - PackageManager packageManager = new PackageManager (repo, Path.Combine (Root, directory, "..", "packages")); - - foreach (var package in Packages) { - packageManager.InstallPackage (package.Id, new SemanticVersion (package.Version)); - } + var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT; + var psi = new ProcessStartInfo (isWindows ? "NuGet.exe" : "mono") { + Arguments = $"{(isWindows ? "" : "\"" + Path.Combine (Root,"NuGet.exe") + "\"")} restore -PackagesDirectory \"{Path.Combine (Root, directory, "..", "packages")}\" \"{Path.Combine (Root, directory, "packages.config")}\"", + }; + var process = Process.Start (psi); + process.WaitForExit (); } public string ProcessSourceTemplate (string source) diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj index dc1e5c2f58f..ea4e0a241ed 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj @@ -1,4 +1,4 @@ - + Debug @@ -38,9 +38,6 @@ ..\..\..\..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll - - ..\..\..\..\packages\NuGet.Core.2.11.1\lib\net40-Client\NuGet.Core.dll - @@ -145,6 +142,10 @@ Include="..\..\..\..\bin\$(Configuration)\lib\xbuild\Xamarin\Android\libzip.so"> PreserveNewest + + PreserveNewest + diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/packages.config b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/packages.config index f9f0d218108..130a8186372 100644 --- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/packages.config +++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/packages.config @@ -1,6 +1,5 @@  - - - + + \ No newline at end of file