I have .netcore2.0 app called MyHelper. MyHelper is referencing a .netstandard2.0 project called B. MyHelper is published as a nuget package.

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:

<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. 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

1

There are 1 best solutions below

0
On BEST ANSWER

<PrivateAssets>all</PrivateAssets> does not work for your situation. 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.

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.

So it cannot solve your needs and cannot deal with the dependency of the nuget package.

Solution 1

Just use Delete task, add this in your project which references the MyHelper nuget package:

<Target Name="RemoveTheFiles" AfterTargets="AfterBuild">
        
        <ItemGroup>
            <File Include="$(TargetDir)B.dll">          
            </File>
        </ItemGroup>

        <Delete Files="@(File)"></Delete>
                    
</Target>