[英]Removing a NuGet package's dependent NuGet packages
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:这是安装在项目中的样子:
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 的评论,这可以通过使用
PackageReference
下的PrivateAssets
元素来实现:
<ItemGroup>
<PackageReference Include="CompanyStyleAnalyzer" Version="1.1.6" />
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.