Skip to content

Commit ffa41aa

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tests] Use the latest NuGet.exe (dotnet#566)
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.
1 parent 1ef403f commit ffa41aa

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

build-tools/xa-prep-tasks/xa-prep-tasks.targets

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<UsingTask AssemblyFile="$(OutputPath)xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.DownloadUri" />
44
<UsingTask AssemblyFile="$(OutputPath)xa-prep-tasks.dll" TaskName="Xamarin.Android.BuildTools.PrepTasks.SystemUnzip" />
55
<Import Project="..\bundle\bundle-path.targets" />
66
<Import Project="..\scripts\XAVersionInfo.targets" />
77
<PropertyGroup>
88
<_AzureBaseUri>https://xamjenkinsartifact.blob.core.windows.net/xamarin-android/xamarin-android/bin/</_AzureBaseUri>
9+
<_NuGetUri>https://dist.nuget.org/win-x86-commandline/latest/nuget.exe</_NuGetUri>
10+
<_NuGetPath>$(MSBuildThisFileDirectory)\..\..\.nuget</_NuGetPath>
911
</PropertyGroup>
1012
<Target Name="_CreateVersion"
1113
DependsOnTargets="GetXAVersionInfo"
@@ -67,6 +69,17 @@
6769
DestinationFiles="$(_BundlePath)"
6870
/>
6971
</Target>
72+
<Target Name="_DownloadNuGet"
73+
Inputs=""
74+
Outputs="$(_NuGetPath)\NuGet.exe">
75+
<MakeDir
76+
Directories="$(_NuGetPath)"
77+
/>
78+
<DownloadUri
79+
SourceUris="$(_NuGetUri)"
80+
DestinationFiles="$(_NuGetPath)\NuGet.exe"
81+
/>
82+
</Target>
7083
<Target Name="_ExtractBundle"
7184
Condition=" Exists('$(_BundlePath)') "
7285
Inputs="$(_BundlePath)"
@@ -84,6 +97,6 @@
8497
</Target>
8598
<Target Name="_DownloadAndExtractBundle"
8699
AfterTargets="Build"
87-
DependsOnTargets="_GetBundleOutputPath;_DownloadBundle;_ExtractBundle">
100+
DependsOnTargets="_GetBundleOutputPath;_DownloadBundle;_ExtractBundle;_DownloadNuGet">
88101
</Target>
89-
</Project>
102+
</Project>

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Common/XamarinProject.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
55
using System.Xml;
66
using Microsoft.Build.Construction;
77
using System.Diagnostics;
88
using System.Text;
9-
using NuGet;
109

1110
namespace Xamarin.ProjectTools
1211
{
@@ -380,12 +379,12 @@ public void NuGetRestore (string directory, string packagesDirectory = null)
380379
if (!Packages.Any ())
381380
return;
382381

383-
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository ("https://packages.nuget.org/api/v2");
384-
PackageManager packageManager = new PackageManager (repo, Path.Combine (Root, directory, "..", "packages"));
385-
386-
foreach (var package in Packages) {
387-
packageManager.InstallPackage (package.Id, new SemanticVersion (package.Version));
388-
}
382+
var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
383+
var psi = new ProcessStartInfo (isWindows ? "NuGet.exe" : "mono") {
384+
Arguments = $"{(isWindows ? "" : "\"" + Path.Combine (Root,"NuGet.exe") + "\"")} restore -PackagesDirectory \"{Path.Combine (Root, directory, "..", "packages")}\" \"{Path.Combine (Root, directory, "packages.config")}\"",
385+
};
386+
var process = Process.Start (psi);
387+
process.WaitForExit ();
389388
}
390389

391390
public string ProcessSourceTemplate (string source)

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Xamarin.ProjectTools.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<PropertyGroup>
44
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -38,9 +38,6 @@
3838
<Reference Include="Microsoft.Web.XmlTransform">
3939
<HintPath>..\..\..\..\packages\Microsoft.Web.Xdt.2.1.1\lib\net40\Microsoft.Web.XmlTransform.dll</HintPath>
4040
</Reference>
41-
<Reference Include="NuGet.Core">
42-
<HintPath>..\..\..\..\packages\NuGet.Core.2.11.1\lib\net40-Client\NuGet.Core.dll</HintPath>
43-
</Reference>
4441
</ItemGroup>
4542
<ItemGroup>
4643
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -145,6 +142,10 @@
145142
Include="..\..\..\..\bin\$(Configuration)\lib\xbuild\Xamarin\Android\libzip.so">
146143
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
147144
</Content>
145+
<Content
146+
Include="..\..\..\..\.nuget\NuGet.exe">
147+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
148+
</Content>
148149
</ItemGroup>
149150
<ItemGroup>
150151
<ProjectReference Include="$(LibZipSharpSourceFullPath)\libZipSharp.csproj">
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
4-
<package id="NuGet.Core" version="2.11.1" targetFramework="net45" />
5-
<package id="Unofficial.Ionic.Zip" version="1.9.1.8" targetFramework="net45" />
3+
<package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net45" />
4+
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net451" />
65
</packages>

0 commit comments

Comments
 (0)