删除NuGet程序包的从属NuGet程序包 [英] Removing a NuGet package's dependent NuGet packages

查看:85
本文介绍了删除NuGet程序包的从属NuGet程序包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的公司创建项目的NuGet软件包,然后将这些NuGet软件包安装到其他内部项目中.目前,我正在使用.NET Standard/Core项目的内置功能来完成此任务.这可以按需工作,但是,我们所有的项目都具有一个包装的NuGet包".安装用于某些代码分析(StyleCop NuGet软件包+公司特定的规则集文件和Json文件).

I am creating NuGet packages of projects for my company, these NuGet packages will then be installed into other internal projects. Currently, I am doing it with the built-in functionality of .NET Standard/Core projects. This works as desired, however, all our projects have a "wrapper NuGet package" installed for some code analysis (StyleCop NuGet package + company-specific ruleset files and Json files).

如果我想将NuCreate包(我创建的)安装到另一个项目中,它将始终添加对样式分析器NuGet包的依赖.

If I want to install a NuGet package (that I created) into another project, it always adds the dependency on our style analyzer NuGet package.

这是安装在项目中的样子:

This is what it looks like installed in a project:

有没有一种方法可以在创建NuGet软件包时删除对特定NuGet软件包的依赖关系?即是否有一种方法可以在(.csproj文件)的行中执行某些操作:

Is there a way that I can remove the dependency on a specific NuGet package upon NuGet package creation? i.e Is there a way that I can do something in the line of (.csproj file):

<ItemGroup>
    <PackageReference Condition="'$(Configuration)'=='Debug'" Include="CompanyStyleAnalyzer" Version="1.1.6" />
</ItemGroup>

但我始终不希望指定实际版本,而是希望删除依赖项,无论我在发行版"(Release)中构建项目时的版本是什么.配置,甚至更好,每次运行Dotnet包时,都指定要在最终包中不包括依赖项.

but instead of specifying the actual version I ALWAYS want to remove the dependency no matter what the version is when I build the project in the "Release" configuration, or even better, every time the Dotnet pack is run, something specifying to not include the dependency in the final package.

这是皱眉"吗?删除项目中依赖项的方法?

Is this a "frowned-upon" way of removing dependencies in the project?

我生成NuGet程序包(在.Net Framework中)的先前方法是使用NuGet CLI -pack命令,然后提取文件并编辑.Nuspec文件以手动删除依赖项.我不想编辑Nuspec文件并重新包装软件包.

The previous way I generated NuGet packages (in .Net Framework), was to use the NuGet CLI - pack command, and then extract the file and edit the .Nuspec file to remove the dependency manually. I do not want to have to edit the Nuspec file and repack the package.

请问有人可以指定我在这方面可以做什么吗?

Can anyone specify what I can do in this regards, please?

推荐答案

根据@ Ian-Kemp的评论,可以使用

As per @Ian-Kemp's comment, this can be achieved by using the PrivateAssets element under your PackageReference:

<ItemGroup>
  <PackageReference Include="CompanyStyleAnalyzer" Version="1.1.6" />
    <PrivateAssets>all</PrivateAssets>
  </PackageReference>
</ItemGroup>

这篇关于删除NuGet程序包的从属NuGet程序包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆