简体   繁体   English

尽管被标记为 PrivateAssets,但 nuget 包中的项目依赖项仍被复制到应用程序 bin 文件夹中

[英]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.

相关问题 标记为内容 - &gt;复制始终的文件未被复制 - File marked as Content -> Copy Always is not being copied 依存关系的依存关系未复制到输出目录 - Dependencies of dependencies not being copied to the output directory Nuget软件包-引用的程序集不作为项目引用包括在内 - Nuget Package - Referenced Assemblies Are Not Being Included As Project References NuGet包的从属DLL未复制到输出文件夹 - Dependent DLLs of a NuGet package not copied to output folder nuget软件包在构建时被删除 - nuget package being removed on build 尽管出现错误“无法加载DLL&#39;SQLite.Interop.dll&#39;”,尽管它位于bin文件夹中 - Getting error “Unable to load DLL 'SQLite.Interop.dll'” despite it being in the bin folder 为什么即使编译时没有引用任何库,也会将dll文件复制到项目的Bin / Debug文件夹中? - why are there dll files copied to my project's Bin/Debug folder upon compilation despite not referencing any of those libraries? NuGet 框架 package 与核心项目的依赖关系 - NuGet Framework package with dependencies from Core project 为什么将此.dll复制到输出文件夹? - Why is this .dll being copied to the output folder? 程序集引用未与自定义nuget包一起添加 - Assembly reference not being added with custom nuget package
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM