Content
project item in .xproj
when using CopyToOutputDirectory=Always
does not work in PackageReference
-based dependencies
#13993
Labels
Functionality:Pack
Priority:3
Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog.
Type:DCR
Design Change Request
Issue moved from dotnet/msbuild#11108
From @guillermooo on Saturday, December 7, 2024 10:45:40 PM
Issue Description
The
Content
MSBuild item type together with theCopyToOutputDirectory
option set toAlways
works differently in Project to Project references (expected result) vsPackageReference
s (unexpected result).Steps to Reproduce
Pre-requisites
Set up workspace
In visual Studio, set
.\A\CHANGELOG.txt
to Build ActionContent
, Copy to Output DirectoryAlways
. Save VS project.Expected output:
Scenario #1 - Project to Project reference does the expected
Scenario #2 - PackageReference does not work in the same way, unexpected
The property
copyToOutput
is set tofalse
, whiletrue
was expected based on<CopyToOutputDirectory>Always</CopyToOutputDirectory>
.Workaraound for Scenario #2
By editing
nuget.spec
manually in the generated package and addingfile copyToOutput=true
where required, the expected result can be achieved.Expected Behavior
The
Content
files should always be copied to the output directory in the consuming project whenCopyToOutputDirectory
is set to a value other thanNever
.Actual Behavior
The
Content
files usingCopyToOutputDirectory=Always
are not copied to the output directory in the consuming proejct when the dependency is declared as aPackageReference
.In this case, the corresponding
nuget.spec
file
element lacks acopyToOutput
property set totrue
, so the defaultfalse
applies. It is expected that thecopyToOutput
property is set totrue
in this case.By manually editing
nuget.spec
after package creation and addingcopyToOutput=true
forfile
elements, the desired behavior can be achieved using the otherwise exactly same package.References
Analysis
Content
in a.xproj
file to always output files to the consuming project's output directory.Content
whenCopyToOutputDirectory
is set to a value other thanNever
inPackageReferece
-based dependency declarations.CopyToOutput
boolean property inContent
that mirrorsfile>copyToOutput
property innuget.spec
. (Seems redundant whenCopyToOutputDirectory
exists.)However, given that the expected result can be obtained when using Project to Project references, this issue appears to be a bug.
Versions & Configurations
.NET info
dotnet --info
Output:
Note: The same problem can be observed in earlier versions of .NET.
The text was updated successfully, but these errors were encountered: