简体   繁体   English

删除 NuGet 包的依赖 NuGet 包

[英]Removing a NuGet package's dependent NuGet packages

Background:背景:

I am creating NuGet packages of projects for my company, these NuGet packages will then be installed into other internal projects.我正在为我的公司创建 NuGet 项目包,然后这些 NuGet 包将安装到其他内部项目中。 Currently, I am doing it with the built-in functionality of .NET Standard/Core projects.目前,我正在使用 .NET Standard/Core 项目的内置功能来做这件事。 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 包”,用于一些代码分析(StyleCop NuGet 包 + 公司特定的规则集文件和 Json 文件)。

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

This is what it looks like installed in a project:这是安装在项目中的样子:

包树

Question:题:

Is there a way that I can remove the dependency on a specific NuGet package upon NuGet package creation?有没有办法在创建 NuGet 包时删除对特定 NuGet 包的依赖? ie Is there a way that I can do something in the line of (.csproj file):即有没有办法让我可以在(.csproj 文件)行中做一些事情:

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

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.但不是指定实际版本,我总是想删除依赖项,无论版本是什么,当我在“发布”配置中构建项目时,或者甚至更好,每次运行 Dotnet 包时,指定不包括最终包中的依赖项。

Is this a "frowned-upon" way of removing dependencies in the project?这是删除项目中依赖项的“不赞成”的方式吗?

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.我之前生成 NuGet 包(在 .Net Framework 中)的方法是使用 NuGet CLI -pack 命令,然后提取文件并编辑 .Nuspec 文件以手动删除依赖项。 I do not want to have to edit the Nuspec file and repack the package.我不想编辑 Nuspec 文件并重新打包包。

Can anyone specify what I can do in this regards, please?任何人都可以指定我在这方面可以做什么吗?

As per @Ian-Kemp's comment, this can be achieved by using the PrivateAssets element under your PackageReference :根据@Ian-Kemp 的评论,这可以通过使用PackageReferencePrivateAssets元素来实现:

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

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

相关问题 从nuget包引用nuget包 - Referencing nuget packages from nuget package Nuget.Server可以在软件包安装上列出软件包但是404 - Nuget.Server can list packages but 404's on package install 如何隐藏依赖的 Nuget 包? - How can I hide dependent Nuget packages? 创建依赖于 netstandard 包的 netcore 3.0 项目的 NuGet 包 - Create a NuGet package of a netcore 3.0 project which is dependent upon netstandard packages 更新软件包时如何防止nuget还原到从属软件包的旧版本 - How to prevent nuget from reverting to older versions of dependent packages when updating a package 无法找到包 ***。 源中不存在具有此 ID 的包:“Local Nuget”、Microsoft Visual Studio 离线包、nuget.org - Unable to find package ***. No packages exist with this id in source(s): "Local Nuget", Microsoft Visual Studio Offline Packages, nuget.org NuGet包的从属DLL未复制到输出文件夹 - Dependent DLLs of a NuGet package not copied to output folder Dotnet 包包括 nuget 包到 output nuget ZEFE90A8E604A7C840E8ZD03A - Dotnet Pack include nuget packages into output nuget package nuget package 与其参考的 nuget 封装之间的不同版本 - Different versions between a nuget package and its referenced nuget packages 对于AppHarbor上的多个软件包,NuGet软件包还原失败 - NuGet package restore fails for several packages on AppHarbor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM