-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Files from referenced assembly are copied despite setting Private to False #8756
Comments
You have this in Main.sln:
MSBuild translates that to a ProjectReference that does not have Private metadata. If you build with The ProjectReference then causes P1/Test.txt to be copied to P2/bin/Debug/net48/Test.txt, even if you delete this Reference from P2/P2.csproj: <ItemGroup>
<Reference Include="P1">
<HintPath>..\P1\bin\Debug\net48\P1.exe</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup> I think you should replace the Reference in P2/P2.csproj with a ProjectReference so that you can control its Private metadata, and delete the dependency from Main.sln. |
Oops, the ProjectReference in P2/P2.csproj.metaproj seems to be used for sequencing only. The item that is used for copying content instead comes from the AssignProjectConfiguration task executed by the AssignProjectConfiguration target. This task gets The CopyLocal metadata is apparently added here: msbuild/src/Tasks/ResolveProjectBase.cs Line 281 in 7e646be
I wonder if that should be changed to add Private=false as well, or alternatively, _GetCopyToOutputDirectoryItemsFromTransitiveProjectReferences could check the CopyLocal metadata.
|
I've tried to use ProjectReference, but it also does not respect Private completely. If I add a project "P0" and reference it from P1 and then use project reference from P2 (i.e. P2 project-references P1 with Private=False, P1 project-references P0) then on build dotnet copies P0 binaries to P2's target folder (and does not copy P1's binaries, so Private is respected but not for dependencies). |
@KalleOlaviNiemitalo Thank you for looking into that. Indeed, I've added dependency into solution for sequencing only. I do not mind using ProjectReference but ideally a non-private reference should not copy anything to the current project. Unfortunately, it does. |
Does it respect CopyLocal? |
It is the same thing, isn't it?
|
Related: #4795 (attempt to express build ordering only) @AlexG5T It sounds that above mentioned case is related to you. In your case you need only So the suggested <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
<OutputType>library</OutputType>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../P1/P1.csproj">
<Private>false</Private>
<ExcludeAssets>all</ExcludeAssets>
</ProjectReference>
</ItemGroup>
</Project> |
Thank you for the workaround. |
Closing as duplicate of #4795 |
Issue Description
A minimal sample project that reproduces the issue:
Main.sln
P1\P1.csproj
P1\Main.cs
P1\Test.txt
P2\P2.csproj
P2\C1.cs
Steps to Reproduce
Now build the project:
Expected Behavior
The expected result is not having Test.txt in the output folder.
When building project one-by-one this doesn't happen:
Actual Behavior
Output folder contains Test.txt.
Analysis
No response
Versions & Configurations
The text was updated successfully, but these errors were encountered: