Skip to content

Instantly share code, notes, and snippets.

@PaulStovell
Created February 19, 2013 04:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PaulStovell/4983109 to your computer and use it in GitHub Desktop.
Save PaulStovell/4983109 to your computer and use it in GitHub Desktop.
A LocalPackageRepository for NuGet that continues to work when packages are being written to it
/// <summary>
/// The local package repository (used for reading packages from the file system) is broken in NuGet.Core because
/// when a package is being written, it refuses to read the packages. This implementation wraps it by ignoring packages
/// that can't be written (either because they are locked or only partially written).
/// </summary>
public class FastLocalPackageRepository : LocalPackageRepository
{
readonly ILog log;
public FastLocalPackageRepository(string physicalPath, ILog log)
: base(physicalPath)
{
this.log = log;
}
protected override IPackage OpenPackage(string path)
{
var fullPath = FileSystem.GetFullPath(path);
try
{
return new ZipPackage(fullPath);
}
catch (Exception ex)
{
log.Warn("Unable to read NuGet package file: " + fullPath + " -- it will be ignored. Error: " + ex.Message, ex);
return new NullPackage();
}
}
public override IQueryable<IPackage> GetPackages()
{
return base.GetPackages().Where(p => p is NullPackage == false);
}
/// <summary>
/// Represents a package file that cannot be read.
/// </summary>
public class NullPackage : IPackage
{
public NullPackage()
{
Id = "null";
Version = new SemanticVersion("0.0.0.0");
}
public string Id { get; private set; }
public SemanticVersion Version { get; private set; }
public string Title { get; private set; }
public IEnumerable<string> Authors { get; private set; }
public IEnumerable<string> Owners { get; private set; }
public Uri IconUrl { get; private set; }
public Uri LicenseUrl { get; private set; }
public Uri ProjectUrl { get; private set; }
public bool RequireLicenseAcceptance { get; private set; }
public string Description { get; private set; }
public string Summary { get; private set; }
public string ReleaseNotes { get; private set; }
public string Language { get; private set; }
public string Tags { get; private set; }
public string Copyright { get; private set; }
public IEnumerable<FrameworkAssemblyReference> FrameworkAssemblies { get; private set; }
public IEnumerable<PackageDependencySet> DependencySets { get; private set; }
public Uri ReportAbuseUrl { get; private set; }
public int DownloadCount { get; private set; }
public IEnumerable<IPackageFile> GetFiles()
{
throw new NotImplementedException();
}
public IEnumerable<FrameworkName> GetSupportedFrameworks()
{
throw new NotImplementedException();
}
public Stream GetStream()
{
throw new NotImplementedException();
}
public bool IsAbsoluteLatestVersion { get; private set; }
public bool IsLatestVersion { get; private set; }
public bool Listed { get; private set; }
public DateTimeOffset? Published { get; private set; }
public IEnumerable<IPackageAssemblyReference> AssemblyReferences { get; private set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment