简体   繁体   English

阻止NuGet包

[英]Block NuGet package

After finally recovering from the System.Net.Http package hell we would like to block the package entirely. 终于在恢复System.Net.Http 到底我们想完全阻止包。

I'm looking for a way to block the package from ever installing, so not blocking or locking a version but the entire package (due to a dependency or developer error). 我正在寻找一种阻止程序包安装的方法,因此不会阻止或锁定版本而是整个程序包(由于依赖项或开发人员错误)。 The block should be in the solution folder of the application so that every developer will have the block once updating from SVN. 该块应位于应用程序的解决方案文件夹中,以便每个开发人员在从SVN更新后都将拥有该块。

I've looked at the NuGet.config and .nuspec documentation but was unable to find such a feature. 我查看了NuGet.config和.nuspec文档,但无法找到这样的功能。 My Google-fu also didn't yield any results. 我的谷歌也没有产生任何结果。 So I was wondering if there was anybody here that knows if and how it can be done. 所以我想知道这里是否有人知道是否以及如何做到这一点。

I've opened up a GitHub issue 我打开了一个GitHub问题

I can maybe offer a workaround. 我可以提供一个解决方法。 We wanted a similar thing (prevent referencing WinForms dependencies) and added a unit test that checks whether specific assemblies are referenced: 我们想要一个类似的东西(防止引用WinForms依赖项)并添加一个单元测试来检查是否引用了特定的程序集:

private static readonly IEnumerable<string> BlockedAssemblies = new List<string>
{   
    "System.Net.Http"
};

[Test]
public void SpecificAssembliesAreNotReferenced()
{
    var asm = Assembly.Load("Your.Assembly.File");

    var refs = asm.GetReferencedAssemblies();
    foreach(var a in refs)
    {
        Assert.False(BlockedAssemblies.Contains (a.Name), $"{a.Name} must not be referenced.");
    }
}

It's not perfect, and doesn't actually block the package from being downloaded, but it prevents accidental referencing and usage of an assembly. 它并不完美,并且实际上不会阻止程序包下载,但它可以防止意外引用和使用程序集。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM