[英]Project dependencies in a nuget package are being copied to the application bin folder despite being marked PrivateAssets
I have .netcore2.0 app called MyHelper.我有一个名为 MyHelper 的 .netcore2.0 应用程序。 MyHelper is referencing a .netstandard2.0 project called B. MyHelper is published as a nuget package. MyHelper 引用了一个名为 B 的 .netstandard2.0 项目。MyHelper 作为 nuget 包发布。
I need to use MyHelper in other projects and solutions only at build time, therefore in my other projects I mark this nuget package as private:我只需要在构建时在其他项目和解决方案中使用 MyHelper,因此在我的其他项目中,我将此 nuget 包标记为私有:
<PackageReference Include="MyHelper" Version="1.0.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
However in the output folder of my other projects consuming this nuget package, B.dll is being present.但是,在我使用此 nuget 包的其他项目的输出文件夹中,存在 B.dll。 I do not want that, as it is meant to be only for build time.我不希望那样,因为它仅用于构建时间。 How do I stop it from being shipped to the applications.我如何阻止它被运送到应用程序。 Thanks谢谢
<PrivateAssets>all</PrivateAssets>
does not work for your situation. <PrivateAssets>all</PrivateAssets>
不适用于您的情况。 When you use this node in Project C , it will prevent another project called Project D which has a project reference to Project C not accessing the nuget package.当您在Project C 中使用此节点时,它将阻止另一个名为Project D的项目,该项目具有对项目 C的项目引用,无法访问 nuget 包。
In other words , when you using this node for the nuget package of the Project C , and other projects which has a reference to Project C , other projects cannot access the nuget package and it is only the private property of the current Project C .换句话说,当您将此节点用于Project C的 nuget 包以及其他引用了Project C 的项目时,其他项目无法访问 nuget 包,它只是当前Project C的私有属性。
So it cannot solve your needs and cannot deal with the dependency of the nuget package.所以它不能解决你的需求,也不能处理nuget包的依赖。
Solution 1解决方案1
Just use Delete
task, add this in your project which references the MyHelper nuget package:只需使用Delete
任务,将其添加到引用MyHelper nuget 包的项目中:
<Target Name="RemoveTheFiles" AfterTargets="AfterBuild">
<ItemGroup>
<File Include="$(TargetDir)B.dll">
</File>
</ItemGroup>
<Delete Files="@(File)"></Delete>
</Target>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.