Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download using new APIs #25800

Merged
merged 2 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Comment on lines +361 to -365
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how this ever worked... We delete and then zip? Seems to have always been like that since my first commit??? #2415

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

were we actually shipping anything extra?

});

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
Loading