Skip to content

Commit

Permalink
(GH-623) Extract Nuspec on Install
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ferventcoder committed Mar 29, 2016
1 parent 3ff48ef commit 0971aeb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/chocolatey.console/chocolatey.console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<HintPath>..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
Expand Down
1 change: 1 addition & 0 deletions src/chocolatey/chocolatey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<HintPath>..\packages\SimpleInjector.2.5.0\lib\net40-client\SimpleInjector.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Management.Automation">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<ManifestReferenceSet>(Enumerable.Select<IGrouping<FrameworkName, IPackageAssemblyReference>, ManifestReferenceSet>(Enumerable.GroupBy<IPackageAssemblyReference, FrameworkName>(package.AssemblyReferences, (Func<IPackageAssemblyReference, FrameworkName>)(f => f.TargetFramework)), (Func<IGrouping<FrameworkName, IPackageAssemblyReference>, ManifestReferenceSet>)(g => new ManifestReferenceSet()
{
TargetFramework = g.Key == (FrameworkName)null ? (string)null : VersionUtility.GetFrameworkString(g.Key),
References = Enumerable.ToList<ManifestReference>(Enumerable.Select<IPackageAssemblyReference, ManifestReference>((IEnumerable<IPackageAssemblyReference>)g, (Func<IPackageAssemblyReference, ManifestReference>)(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
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 0971aeb

Please sign in to comment.