From 0971aeb0a717fd3852cd651cf7ea37078d3d94b6 Mon Sep 17 00:00:00 2001 From: Rob Reynolds Date: Mon, 28 Mar 2016 23:12:29 -0500 Subject: [PATCH] (GH-623) Extract Nuspec on Install When querying local file information, it is much quicker when there is a local nuspec file there as well. Especiallly when the nupkg is larger due to size of embedded files. --- .../chocolatey.console.csproj | 1 + src/chocolatey/chocolatey.csproj | 1 + .../nuget/ChocolateyLocalPackageRepository.cs | 27 +++++++++++++++++++ .../infrastructure.app/nuget/NugetCommon.cs | 2 +- 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/chocolatey.console/chocolatey.console.csproj b/src/chocolatey.console/chocolatey.console.csproj index 932a406ac6..e4ac79c5a6 100644 --- a/src/chocolatey.console/chocolatey.console.csproj +++ b/src/chocolatey.console/chocolatey.console.csproj @@ -93,6 +93,7 @@ ..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll + diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj index a235d7d852..a8b316992e 100644 --- a/src/chocolatey/chocolatey.csproj +++ b/src/chocolatey/chocolatey.csproj @@ -56,6 +56,7 @@ ..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll + diff --git a/src/chocolatey/infrastructure.app/nuget/ChocolateyLocalPackageRepository.cs b/src/chocolatey/infrastructure.app/nuget/ChocolateyLocalPackageRepository.cs index 7030cde28a..74be79818c 100644 --- a/src/chocolatey/infrastructure.app/nuget/ChocolateyLocalPackageRepository.cs +++ b/src/chocolatey/infrastructure.app/nuget/ChocolateyLocalPackageRepository.cs @@ -15,6 +15,11 @@ namespace chocolatey.infrastructure.app.nuget { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Runtime.Versioning; using NuGet; // ReSharper disable InconsistentNaming @@ -44,8 +49,30 @@ public ChocolateyLocalPackageRepository(IPackagePathResolver pathResolver, IFile public override void AddPackage(IPackage package) { string packageFilePath = GetPackageFilePath(package); + if (PackageSaveMode.HasFlag(PackageSaveModes.Nuspec)) + { + string manifestFilePath = GetManifestFilePath(package.Id, package.Version); + Manifest manifest = Manifest.Create(package); + manifest.Metadata.ReferenceSets = Enumerable.ToList(Enumerable.Select, ManifestReferenceSet>(Enumerable.GroupBy(package.AssemblyReferences, (Func)(f => f.TargetFramework)), (Func, ManifestReferenceSet>)(g => new ManifestReferenceSet() + { + TargetFramework = g.Key == (FrameworkName)null ? (string)null : VersionUtility.GetFrameworkString(g.Key), + References = Enumerable.ToList(Enumerable.Select((IEnumerable)g, (Func)(p => new ManifestReference() + { + File = p.Name + }))) + }))); + FileSystem.AddFileWithCheck(manifestFilePath, manifest.Save); + } + FileSystem.AddFileWithCheck(packageFilePath, package.GetStream); } + + private string GetManifestFilePath(string packageId, SemanticVersion version) + { + string packageDirectory = PathResolver.GetPackageDirectory(packageId, version); + string path2 = packageDirectory + Constants.ManifestExtension; + return Path.Combine(packageDirectory, path2); + } } // ReSharper restore InconsistentNaming diff --git a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs index b290cfa892..eae8c9b5d7 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetCommon.cs @@ -45,7 +45,7 @@ public static IPackagePathResolver GetPathResolver(ChocolateyConfiguration confi public static IPackageRepository GetLocalRepository(IPackagePathResolver pathResolver, IFileSystem nugetPackagesFileSystem) { IPackageRepository localRepository = new ChocolateyLocalPackageRepository(pathResolver, nugetPackagesFileSystem); - localRepository.PackageSaveMode = PackageSaveModes.Nupkg; + localRepository.PackageSaveMode = PackageSaveModes.Nupkg | PackageSaveModes.Nuspec; return localRepository; }