Skip to content

Instantly share code, notes, and snippets.

@mattleibow
Last active August 14, 2021 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattleibow/a35c882977c96a77f37bb5add6b1ce07 to your computer and use it in GitHub Desktop.
Save mattleibow/a35c882977c96a77f37bb5add6b1ce07 to your computer and use it in GitHub Desktop.
#addin "nuget:?package=NuGet.Common&version=5.11.0"
#addin "nuget:?package=NuGet.Configuration&version=5.11.0"
#addin "nuget:?package=NuGet.Frameworks&version=5.11.0"
#addin "nuget:?package=NuGet.Packaging&version=5.11.0"
#addin "nuget:?package=NuGet.Protocol&version=5.11.0"
#addin "nuget:?package=NuGet.Versioning&version=5.11.0"
using NuGet.Common;
using NuGet.Packaging;
using NuGet.Packaging.Core;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;
Task("Default").Does(async () =>
{
var gitSha = EnvironmentVariable("GIT_SHA");
var destRoot = EnvironmentVariable("System_DefaultWorkingDirectory") ?? ".";
if (!DirectoryExists(destRoot))
CreateDirectory(destRoot);
var OLD_FEED = "https://nugetized.blob.core.windows.net/skiasharp-eap/index.json";
var NEW_FEED = "https://aka.ms/skiasharp-eap/index.json";
var oldSource = Repository.Factory.GetCoreV3(OLD_FEED);
var oldCache = new SourceCacheContext();
var oldLogger = NullLogger.Instance;
var oldMetadata = await oldSource.GetResourceAsync<PackageMetadataResource>();
var newSource = Repository.Factory.GetCoreV3(NEW_FEED);
var newCache = new SourceCacheContext();
var newLogger = NullLogger.Instance;
var newMetadata = await newSource.GetResourceAsync<PackageMetadataResource>();
var oldPackage = new PackageIdentity("_NativeAssets", NuGetVersion.Parse("0.0.0-commit." + gitSha));
var newExistingPackage = await newMetadata.GetMetadataAsync(oldPackage, newCache, newLogger, default);
if (newExistingPackage == null)
{
Information("Downloading: " + oldPackage);
var oldById = await oldSource.GetResourceAsync<FindPackageByIdResource>();
using (var oldDownloader = await oldById.GetPackageDownloaderAsync(oldPackage, oldCache, oldLogger, default))
{
var fileName = oldPackage.ToString() + ".nupkg";
fileName = System.IO.Path.Combine(destRoot, fileName);
Information("Saving to: " + fileName);
await oldDownloader.CopyNupkgFileToAsync(fileName, default);
}
}
else
{
Information("Package existed: " + oldPackage);
}
Information("Done!");
});
RunTarget("Default");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment