Skip to content

Commit

Permalink
Download using new APIs (#25800)
Browse files Browse the repository at this point in the history
* Download using new APIs

mono is no longer found on machines

* fix
  • Loading branch information
mattleibow authored Nov 13, 2024
1 parent 8b7989a commit 353f1a3
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 11 deletions.
16 changes: 7 additions & 9 deletions eng/cake/dotnet.cake
Original file line number Diff line number Diff line change
Expand Up @@ -345,24 +345,22 @@ Task("dotnet-pack-maui")

Task("dotnet-pack-additional")
.WithCriteria(RunPackTarget())
.Does(() =>
.Does(async () =>
{
// Download some additional symbols that need to be archived along with the maui symbols:
// - _NativeAssets.windows
// - libSkiaSharp.pdb
// - libHarfBuzzSharp.pdb
var assetsDir = $"./artifacts/additional-assets";
var nativeAssetsVersion = XmlPeek("./eng/Versions.props", "/Project/PropertyGroup/_SkiaSharpNativeAssetsVersion");
NuGetInstall("_NativeAssets.windows", new NuGetInstallSettings
{
Version = nativeAssetsVersion,
ExcludeVersion = true,
OutputDirectory = assetsDir,
Source = new[] { "https://pkgs.dev.azure.com/xamarin/public/_packaging/SkiaSharp/nuget/v3/index.json" },
});
await DownloadNuGetPackageAsync(
"_NativeAssets.windows",
nativeAssetsVersion,
assetsDir,
"https://pkgs.dev.azure.com/xamarin/public/_packaging/SkiaSharp/nuget/v3/index.json");
Zip(assetsDir, $"{assetsDir}.zip");
foreach (var nupkg in GetFiles($"{assetsDir}/**/*.nupkg"))
DeleteFile(nupkg);
Zip(assetsDir, $"{assetsDir}.zip");
});

Task("dotnet-pack-library-packs")
Expand Down
44 changes: 43 additions & 1 deletion eng/cake/helpers.cake
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#addin "nuget:?package=NuGet.Packaging&version=6.7.0"
#addin "nuget:?package=NuGet.Protocol&version=6.7.0"

using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
using NuGet.Versioning;

bool isCleanSet = HasArgument("clean") || IsTarget("clean");

Task("Clean")
Expand Down Expand Up @@ -108,4 +118,36 @@ bool IsTarget(string target) =>
Argument<string>("target", "Default").Equals(target, StringComparison.InvariantCultureIgnoreCase);

bool TargetStartsWith(string target) =>
Argument<string>("target", "Default").StartsWith(target, StringComparison.InvariantCultureIgnoreCase);
Argument<string>("target", "Default").StartsWith(target, StringComparison.InvariantCultureIgnoreCase);

public async Task DownloadNuGetPackageAsync(string packageId, string version, string outputDirectory, string feedUri)
{
// Create a source repository
var repository = Repository.Factory.GetCoreV3(feedUri);

// Find the package
var resource = await repository.GetResourceAsync<FindPackageByIdResource>();
var packageVersion = NuGetVersion.Parse(version);
var cacheContext = new SourceCacheContext();

// Set up logging (optional, use NullLogger if you don't need logging)
ILogger logger = NullLogger.Instance;

// Download the package to the output directory
EnsureDirectoryExists(outputDirectory);
var packagePath = System.IO.Path.Combine(outputDirectory, $"{packageId}.{version}.nupkg");

using (var fileStream = new FileStream(packagePath, FileMode.Create, FileAccess.Write, FileShare.None))
{
// Download package
var success = await resource.CopyNupkgToStreamAsync(
packageId, packageVersion, fileStream, cacheContext, logger, default);

if (!success)
{
throw new Exception("Failed to download the package.");
}

Information("Package '{0} v{1}' downloaded successfully to {2}", packageId, version, packagePath);
}
}
2 changes: 1 addition & 1 deletion eng/devices/windows.cake
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Task("GenerateMsixCert")
{
Information("Generating cert");
var rsa = RSA.Create();
var req = new CertificateRequest("CN=" + certCN, rsa, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
var req = new CertificateRequest("CN=" + certCN, rsa, System.Security.Cryptography.HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);

req.CertificateExtensions.Add(new X509EnhancedKeyUsageExtension(new OidCollection
{
Expand Down

0 comments on commit 353f1a3

Please sign in to comment.