diff --git a/src/GprTool/NuGetUtilities.cs b/src/GprTool/NuGetUtilities.cs index 9a47388..a2e4231 100644 --- a/src/GprTool/NuGetUtilities.cs +++ b/src/GprTool/NuGetUtilities.cs @@ -11,30 +11,15 @@ namespace GprTool { public class PackageFile { - public string Filename { get; set; } public string Owner { get; set; } public string RepositoryName { get; set; } public string RepositoryUrl { get; set; } + public bool ShouldRewriteNuspec { get; set; } public bool IsNuspecRewritten { get; set; } - public string FilenameWithoutGprPrefixAndPath - { - get - { - var gprIndex = !IsNuspecRewritten ? -1 : Filename.LastIndexOf("_gpr", StringComparison.OrdinalIgnoreCase); - if (gprIndex == -1) - { - return Filename; - } - - // Support case sensitive filename extensions (e.g. test_gpr.NuPkg -> test.NuPkg) - - var filenameUntilGpr = Filename.Substring(0, gprIndex); - var filenameExcludingGpr = Filename.Substring(gprIndex + 4); - - return Path.GetFileName(filenameUntilGpr + filenameExcludingGpr); - } - } + public string Filename { get; set; } + public string FilenameAbsolutePath { get; set; } + public string FilenameWithoutGprPrefix { get; set; } } public class NuGetUtilities @@ -86,24 +71,10 @@ public static bool BuildOwnerAndRepositoryFromUrl(PackageFile packageFile, strin return true; } - public static bool TryReadPackageFileMetadata(PackageFile packageFile) + public static bool BuildOwnerAndRepositoryFromUrlFromNupkg(PackageFile packageFile) { - if (!File.Exists(packageFile.Filename)) - { - return false; - } - - Manifest manifest; - - try - { - manifest = ReadNupkgManifest(packageFile.Filename); - } - catch (Exception) - { - return false; - } - + var manifest = ReadNupkgManifest(packageFile.FilenameAbsolutePath); + return BuildOwnerAndRepositoryFromUrl(packageFile, manifest.Metadata.Repository?.Url); } @@ -111,7 +82,9 @@ public static PackageFile BuildPackageFile(string filename, string repositoryUrl { var packageFile = new PackageFile { - Filename = filename + Filename = Path.GetFileName(filename), + FilenameWithoutGprPrefix = Path.GetFileName(filename), + FilenameAbsolutePath = Path.GetFullPath(filename) }; BuildOwnerAndRepositoryFromUrl(packageFile, repositoryUrl); @@ -126,35 +99,29 @@ public static Manifest ReadNupkgManifest(string nupkgPath) return Manifest.ReadFrom(packageArchiveReader.GetNuspec(), false); } - public static bool ShouldRewriteNupkg(string nupkgPath, string repositoryUrl, NuGetVersion nuGetVersion = null) + public static bool ShouldRewriteNupkg(PackageFile packageFile, NuGetVersion nuGetVersion = null) { - if (nupkgPath == null) throw new ArgumentNullException(nameof(nupkgPath)); + if (packageFile == null) throw new ArgumentNullException(nameof(packageFile)); - var manifest = ReadNupkgManifest(nupkgPath); + var manifest = ReadNupkgManifest(packageFile.FilenameAbsolutePath); if (nuGetVersion != null && !nuGetVersion.Equals(manifest.Metadata.Version)) { return true; } - return !string.Equals(repositoryUrl, manifest.Metadata.Repository?.Url, StringComparison.OrdinalIgnoreCase); + return !string.Equals(packageFile.RepositoryUrl, manifest.Metadata.Repository?.Url, StringComparison.OrdinalIgnoreCase); } - public static string RewriteNupkg(string nupkgPath, string repositoryUrl, NuGetVersion nuGetVersion = null) + public static void RewriteNupkg(PackageFile packageFile, NuGetVersion nuGetVersion = null) { - if (nupkgPath == null) throw new ArgumentNullException(nameof(nupkgPath)); - if (repositoryUrl == null) throw new ArgumentNullException(nameof(repositoryUrl)); - - var randomDirectoryId = Guid.NewGuid().ToString("N"); - var nupkgFilename = Path.GetFileName(nupkgPath); - var nupkgFilenameWithoutExt = Path.GetFileNameWithoutExtension(nupkgFilename); - var nupkgWorkingDirectoryAbsolutePath = Path.GetDirectoryName(nupkgPath); - var workingDirectory = Path.Combine(nupkgWorkingDirectoryAbsolutePath, $"{nupkgFilenameWithoutExt}_{randomDirectoryId}"); - - using var tmpDirectory = new DisposableDirectory(workingDirectory); - using var packageArchiveReader = new PackageArchiveReader(nupkgPath.ReadSharedToStream(), false); - using var nuspecMemoryStream = new MemoryStream(); - + if (packageFile == null) throw new ArgumentNullException(nameof(packageFile)); + + var randomId = Guid.NewGuid().ToString("N"); + + using var packageArchiveReader = new PackageArchiveReader( + packageFile.FilenameAbsolutePath.ReadSharedToStream(), false); + var nuspecXDocument = packageArchiveReader.NuspecReader.Xml; var packageXElement = nuspecXDocument.Single("package"); var metadataXElement = packageXElement.Single("metadata"); @@ -174,34 +141,44 @@ public static string RewriteNupkg(string nupkgPath, string repositoryUrl, NuGetV if (repositoryXElement == null) { repositoryXElement = new XElement("repository"); - repositoryXElement.SetAttributeValue("url", repositoryUrl); + repositoryXElement.SetAttributeValue("url", packageFile.RepositoryUrl); repositoryXElement.SetAttributeValue("type", "git"); metadataXElement.Add(repositoryXElement); } else { - repositoryXElement.SetAttributeValue("url", repositoryUrl); + repositoryXElement.SetAttributeValue("url", packageFile.RepositoryUrl); repositoryXElement.SetAttributeValue("type", "git"); } + using var nuspecMemoryStream = new MemoryStream(); nuspecXDocument.Save(nuspecMemoryStream); nuspecMemoryStream.Seek(0, SeekOrigin.Begin); - ZipFile.ExtractToDirectory(nupkgPath, tmpDirectory.WorkingDirectory, true); + var packageFileWorkingDirectoryAbsolutePath = Path.GetDirectoryName(packageFile.FilenameAbsolutePath); + var packageFileRewriteWorkingDirectory = Path.Combine(packageFileWorkingDirectoryAbsolutePath, + $"{packageId}.{nuGetVersion}_{randomId}"); + + using var tmpDirectory = new DisposableDirectory(packageFileRewriteWorkingDirectory); + + ZipFile.ExtractToDirectory(packageFile.FilenameAbsolutePath, tmpDirectory.WorkingDirectory); var nuspecDstFilename = Path.Combine(tmpDirectory.WorkingDirectory, $"{packageId}.nuspec"); File.WriteAllBytes(nuspecDstFilename, nuspecMemoryStream.ToArray()); using var outputStream = new MemoryStream(); - var packageBuilder = new PackageBuilder(nuspecMemoryStream, tmpDirectory.WorkingDirectory, propertyProvider => throw new NotImplementedException()); + var packageBuilder = new PackageBuilder(nuspecMemoryStream, tmpDirectory.WorkingDirectory, + propertyProvider => throw new NotImplementedException()); packageBuilder.Save(outputStream); - var nupkgDstFilenameAbsolutePath = Path.Combine(nupkgWorkingDirectoryAbsolutePath, $"{packageId}.{nuGetVersion}_gpr.nupkg"); - - File.WriteAllBytes(nupkgDstFilenameAbsolutePath, outputStream.ToArray()); + packageFile.FilenameAbsolutePath = Path.Combine(packageFileWorkingDirectoryAbsolutePath, + $"{packageId}.{nuGetVersion}_{randomId}_gpr.nupkg"); + packageFile.Filename = Path.GetFileName(packageFile.FilenameAbsolutePath); + packageFile.FilenameWithoutGprPrefix = $"{packageId}.{nuGetVersion}.nupkg"; + packageFile.IsNuspecRewritten = true; - return nupkgDstFilenameAbsolutePath; + File.WriteAllBytes(packageFile.FilenameAbsolutePath, outputStream.ToArray()); } public static string FindTokenInNuGetConfig(Action warning = null) diff --git a/src/GprTool/Program.cs b/src/GprTool/Program.cs index f208c0d..4090fd8 100644 --- a/src/GprTool/Program.cs +++ b/src/GprTool/Program.cs @@ -9,6 +9,7 @@ using System.Threading; using DotNet.Globbing; using McMaster.Extensions.CommandLineUtils; +using NuGet.Packaging; using NuGet.Versioning; using RestSharp; using RestSharp.Authenticators; @@ -333,9 +334,10 @@ static IAsyncPolicy BuildRetryAsyncPolicy(int retryNumber, int re var retryPolicy = Policy // http://restsharp.org/usage/exceptions.html - .HandleResult(x => !cancellationToken.IsCancellationRequested + .HandleResult(x => !cancellationToken.IsCancellationRequested && x.StatusCode != HttpStatusCode.Unauthorized - && x.StatusCode != HttpStatusCode.Conflict + && x.StatusCode != HttpStatusCode.Conflict + && x.StatusCode != HttpStatusCode.BadRequest && x.StatusCode != HttpStatusCode.OK) .WaitAndRetryAsync(retryNumber, retryAttempt => TimeSpan.FromSeconds(retrySleepSeconds)); @@ -351,7 +353,7 @@ protected override async Task OnExecute(CommandLineApplication app) var isGlobPattern = glob.IsGlobPattern(); NuGetVersion nuGetVersion = null; - if (RepositoryUrl != null && Version != null && !NuGetVersion.TryParse(Version, out nuGetVersion)) + if (Version != null && !NuGetVersion.TryParse(Version, out nuGetVersion)) { Console.WriteLine($"Invalid version: {Version}"); return; @@ -383,7 +385,7 @@ protected override async Task OnExecute(CommandLineApplication app) foreach (var packageFile in packageFiles) { - if (!File.Exists(packageFile.Filename)) + if (!File.Exists(packageFile.FilenameAbsolutePath)) { Console.WriteLine($"Package file was not found: {packageFile}"); return; @@ -391,7 +393,7 @@ protected override async Task OnExecute(CommandLineApplication app) if (RepositoryUrl == null) { - NuGetUtilities.TryReadPackageFileMetadata(packageFile); + NuGetUtilities.BuildOwnerAndRepositoryFromUrlFromNupkg(packageFile); } else { @@ -404,19 +406,13 @@ protected override async Task OnExecute(CommandLineApplication app) { Console.WriteLine( $"Project is missing a valid XML element value: {packageFile.RepositoryUrl}. " + - $"Package filename: {packageFile.Filename} " + + $"Package filename: {packageFile.FilenameAbsolutePath} " + "Please use --repository option to set a valid upstream GitHub repository. " + "Additional details are available at: https://docs.microsoft.com/en-us/dotnet/core/tools/csproj#repositoryurl"); return; } - if (!NuGetUtilities.ShouldRewriteNupkg(packageFile.Filename, packageFile.RepositoryUrl, nuGetVersion)) - { - continue; - } - - packageFile.Filename = NuGetUtilities.RewriteNupkg(packageFile.Filename, packageFile.RepositoryUrl, nuGetVersion); - packageFile.IsNuspecRewritten = true; + packageFile.ShouldRewriteNuspec = NuGetUtilities.ShouldRewriteNupkg(packageFile, nuGetVersion); } const string user = "GprTool"; @@ -437,51 +433,79 @@ protected override async Task OnExecute(CommandLineApplication app) { try { - await UploadPackageAsync(); + await concurrencySemaphore.WaitAsync(CancellationToken); + + NuGetVersion packageVersion; + if (packageFile.ShouldRewriteNuspec) + { + NuGetUtilities.RewriteNupkg(packageFile, nuGetVersion); + + var manifest = NuGetUtilities.ReadNupkgManifest(packageFile.FilenameAbsolutePath); + packageVersion = manifest.Metadata.Version; + } + else + { + var manifest = NuGetUtilities.ReadNupkgManifest(packageFile.FilenameAbsolutePath); + packageVersion = manifest.Metadata.Version; + } + + await using var packageStream = packageFile.FilenameAbsolutePath.ReadSharedToStream(); + + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: " + + $"Repository url: {packageFile.RepositoryUrl}. " + + $"Version: {packageVersion}. " + + $"Size: {packageStream.Length} bytes. "); + + + return await retryPolicy.ExecuteAsync(() => UploadPackageAsync(packageStream)); } finally { - concurrencySemaphore.Dispose(); + concurrencySemaphore.Release(); } }); - async Task UploadPackageAsync() + async Task UploadPackageAsync(MemoryStream packageStream) { - await concurrencySemaphore.WaitAsync(); + if (packageStream == null) throw new ArgumentNullException(nameof(packageStream)); var request = new RestRequest(Method.PUT); - await using var packageStream = packageFile.Filename.ReadSharedToStream(); - request.AddFile("package", packageStream.ToArray(), packageFile.FilenameWithoutGprPrefixAndPath); - var client = WithRestClient($"https://nuget.pkg.github.com/{packageFile.Owner}/", x => { x.Authenticator = new HttpBasicAuthenticator(user, token); }); - Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefixAndPath}]: Uploading package."); + packageStream.Seek(0, SeekOrigin.Begin); + + request.AddFile("package", packageStream.CopyTo, packageFile.FilenameWithoutGprPrefix, packageStream.Length); + + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: Uploading package."); - var response = await retryPolicy.ExecuteAsync(() => client.ExecuteAsync(request, CancellationToken)); + var response = await client.ExecuteAsync(request, CancellationToken); if (response.StatusCode == HttpStatusCode.OK) { - Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefixAndPath}]: {response.Content}"); - return; + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: {response.Content}"); + goto done; } var nugetWarning = response.Headers.FirstOrDefault(h => h.Name.Equals("X-Nuget-Warning", StringComparison.OrdinalIgnoreCase)); if (nugetWarning != null) { - Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefixAndPath}]: {nugetWarning.Value}"); - return; + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: {nugetWarning.Value}"); + goto done; } - Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefixAndPath}]: {response.StatusDescription}"); + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: {response.StatusDescription}"); foreach (var header in response.Headers) { - Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefixAndPath}]: {header.Name}: {header.Value}"); + Console.WriteLine($"[{packageFile.FilenameWithoutGprPrefix}]: {header.Name}: {header.Value}"); } + + done: + return response; } }); diff --git a/test/GprTool.Tests/NuGetUtilitiesTests.cs b/test/GprTool.Tests/NuGetUtilitiesTests.cs index 5235993..261cccd 100644 --- a/test/GprTool.Tests/NuGetUtilitiesTests.cs +++ b/test/GprTool.Tests/NuGetUtilitiesTests.cs @@ -149,9 +149,14 @@ public void UpdatePackageSourceCredentials() [TestCase(" https://github.com/jcansdale/gpr ", "jcansdale", "gpr", "https://github.com/jcansdale/gpr", Description = "Whitespace")] public void BuildPackageFile(string repositoryUrl, string expectedOwner, string expectedRepositoryName, string expectedGithubRepositoryUrl) { - var packageFile = NuGetUtilities.BuildPackageFile("test.nupkg", repositoryUrl); + var packageFile = NuGetUtilities.BuildPackageFile("c:\\test\\test.nupkg", repositoryUrl); + packageFile.IsNuspecRewritten = true; + Assert.That(packageFile, Is.Not.Null); Assert.That(packageFile.Filename, Is.EqualTo("test.nupkg")); + Assert.That(packageFile.FilenameWithoutGprPrefix, Is.EqualTo("test.nupkg")); + Assert.That(packageFile.FilenameAbsolutePath, Is.EqualTo("c:\\test\\test.nupkg")); + if (expectedGithubRepositoryUrl == null) { Assert.Null(packageFile.Owner); @@ -159,28 +164,41 @@ public void BuildPackageFile(string repositoryUrl, string expectedOwner, string Assert.That(packageFile.RepositoryUrl, Is.Null); return; } + Assert.That(packageFile.Owner, Is.EqualTo(expectedOwner)); Assert.That(packageFile.RepositoryName, Is.EqualTo(expectedRepositoryName)); Assert.That(packageFile.RepositoryUrl, Is.Not.Null); Assert.That(packageFile.RepositoryUrl, Is.EqualTo(expectedGithubRepositoryUrl)); } - [TestCase("test.nupkg", "test.nupkg")] - [TestCase("test.snupkg", "test.snupkg")] - [TestCase("test_gpr.nupkg", "test.nupkg")] - [TestCase("test_gpr.snupkg", "test.snupkg")] - [TestCase("test_GPR.nupkg", "test.nupkg")] - [TestCase("test_GPR.snupkg", "test.snupkg")] - [TestCase("test_GPR.nUpkG", "test.nUpkG", Description = "Preserves casing")] - [TestCase("test_GPR.SnuPkg", "test.SnuPkg", Description = "Preserves casing")] - public void PackageFile_FilenameWithoutGprPrefixAndPath(string filename, string expectedFilename) + [TestCase("jcansdale/gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("jcansdale//gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("/jcansdale/gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("http://github.com/jcansdale/gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("https://github.com/jcansdale/gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("https://github.com/jcansdale\\gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase("https://github.com/jcansdale///////gpr", "jcansdale", "gpr", "https://github.com/jcansdale/gpr")] + [TestCase(" https://github.com/jcansdale/gpr ", "jcansdale", "gpr", "https://github.com/jcansdale/gpr", Description = "Whitespace")] + public void BuildOwnerAndRepositoryFromUrlFromNupkg(string repositoryUrl, string expectedOwner, string expectedRepositoryName, string expectedGithubRepositoryUrl) { - var packageFile = new PackageFile + using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext(manifest => { - Filename = filename, - IsNuspecRewritten = true - }; - Assert.That(packageFile.FilenameWithoutGprPrefixAndPath, Is.EqualTo(expectedFilename)); + manifest.Metadata.Repository = new RepositoryMetadata + { + Url = repositoryUrl, + Type = "git" + }; + })); + + packageBuilderContext.Build(); + + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, null); + + Assert.True(NuGetUtilities.BuildOwnerAndRepositoryFromUrlFromNupkg(packageFile)); + + Assert.That(packageFile.Owner, Is.EqualTo(expectedOwner)); + Assert.That(packageFile.RepositoryName, Is.EqualTo(expectedRepositoryName)); + Assert.That(packageFile.RepositoryUrl, Is.EqualTo(expectedGithubRepositoryUrl)); } [Test] @@ -223,10 +241,11 @@ public void ShouldRewriteNupkg_Version(string currentVersion, string updatedVers packageBuilderContext.Build(); + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, repositoryUrl); + Assert.That( - NuGetUtilities.ShouldRewriteNupkg( - packageBuilderContext.NupkgFilename, - repositoryUrl, NuGetVersion.Parse(updatedVersion)), Is.EqualTo(shouldUpdateVersion)); + NuGetUtilities.ShouldRewriteNupkg(packageFile, + NuGetVersion.Parse(updatedVersion)), Is.EqualTo(shouldUpdateVersion)); } [TestCase("https://github.com/owner/repo.git", "https://github.com/owner/repo.git", false, Description = "Equals")] @@ -253,10 +272,9 @@ public void ShouldRewriteNupkg_RepositoryUrl(string currentRepositoryUrl, string packageBuilderContext.Build(); - Assert.That( - NuGetUtilities.ShouldRewriteNupkg( - packageBuilderContext.NupkgFilename, - updatedRepositoryUrl), Is.EqualTo(shouldUpdateRepositoryUrl)); + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, updatedRepositoryUrl); + + Assert.That(NuGetUtilities.ShouldRewriteNupkg(packageFile), Is.EqualTo(shouldUpdateRepositoryUrl)); } [TestCase("randomvalue")] @@ -276,26 +294,27 @@ public void ShouldRewriteNupkg_Ignores_RepositoryType(string repositoryType) packageBuilderContext.Build(); - Assert.That( - NuGetUtilities.ShouldRewriteNupkg( - packageBuilderContext.NupkgFilename, - currentRepositoryUrl), Is.EqualTo(false)); + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, currentRepositoryUrl); + + Assert.That(NuGetUtilities.ShouldRewriteNupkg(packageFile), Is.EqualTo(false)); } [TestCase("https://github.com/owner/repo.git", "https://github.com/owner/repo.git")] [TestCase("https://github.com/owner/repo", "https://github.com/owner/repo")] public void RewriteNuspec(string repositoryUrl, string expectedRepositoryUrl) { - using var originalPackageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext( + using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext( manifest => { manifest.Metadata.Repository = null; })); - originalPackageBuilderContext.Build(); + packageBuilderContext.Build(); + + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, repositoryUrl); - var rewrittenNupkgAbsolutePath = NuGetUtilities.RewriteNupkg(originalPackageBuilderContext.NupkgFilename, - repositoryUrl, NuGetVersion.Parse("2.0.0")); - using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(rewrittenNupkgAbsolutePath)); + NuGetUtilities.RewriteNupkg(packageFile, NuGetVersion.Parse("2.0.0")); + + using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(packageFile.FilenameAbsolutePath)); var rewrittenNupkgPackageIdentity = rewrittenNupkgPackageReader.GetIdentity(); var rewrittenNupkgRepositoryMetadata = rewrittenNupkgPackageReader.NuspecReader.GetRepositoryMetadata(); @@ -311,7 +330,7 @@ public void RewriteNuspec(string repositoryUrl, string expectedRepositoryUrl) [Test] public void RewriteNuspec_Overwrites_Existing_Repository_Url() { - using var originalPackageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext( + using var packageBuilderContext = new PackageBuilderContext(TmpDirectoryPath, new NuspecContext( manifest => { manifest.Metadata.Repository = new RepositoryMetadata @@ -320,11 +339,13 @@ public void RewriteNuspec_Overwrites_Existing_Repository_Url() Type = "google" }; })); - originalPackageBuilderContext.Build(); + packageBuilderContext.Build(); + + var packageFile = NuGetUtilities.BuildPackageFile(packageBuilderContext.NupkgFilename, "https://github.com/owner/repo"); + + NuGetUtilities.RewriteNupkg(packageFile, NuGetVersion.Parse("2.0.0")); - var rewrittenNupkgAbsolutePath = NuGetUtilities.RewriteNupkg(originalPackageBuilderContext.NupkgFilename, - "https://github.com/owner/repo", NuGetVersion.Parse("2.0.0")); - using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(rewrittenNupkgAbsolutePath)); + using var rewrittenNupkgPackageReader = new PackageArchiveReader(File.OpenRead(packageFile.FilenameAbsolutePath)); var rewrittenNupkgPackageIdentity = rewrittenNupkgPackageReader.GetIdentity(); var rewrittenNupkgRepositoryMetadata = rewrittenNupkgPackageReader.NuspecReader.GetRepositoryMetadata();