删除 NuGet 包的依赖 NuGet 包 [英] Removing a NuGet package's dependent NuGet packages

查看:46
本文介绍了删除 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).

如果我想将 NuGet 包(我创建的)安装到另一个项目中,它总是会添加对我们的样式分析器 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>

但是当我在发布"中构建项目时,无论版本是什么,我总是想删除依赖项而不是指定实际版本.配置,或者甚至更好,每次运行 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 的评论,这可以通过使用 您的 PackageReference<下的 PrivateAssets 元素/代码>:

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天全站免登陆