❔ How can I prevent content files from ProjectReferences being copied on build?
I have a test project (
Tests.csproj
) that contains an nlog.config file which needs to be copied to its output directory on build. Being a test project, it references another project (App.csproj
) in my solution that also contains an nlog.config file. The nlog.config files have different content so they are not redundant. In both nlog.config files have CopyToOutputDirectory
set to PreserveNewest
.
When I build Tests.csproj
and inspect the resulting msbuild.binlog
file, I see double writes for Tests\bin\Release\nlog.config
. I suspect/hope this is due to App.csproj
's nlog.config being copied into Tests\bin\Release
, and then Tests.csproj
's nlog.config being copied and overwriting it.
With NuGet package references I can control this with <ExcludeAssets>contentfiles</ExcludeAssets>
. Is there a similar directive I can use for project references? ExcludeAssets didn't work.
Also, I'd be interested in solutions to this problem for both SDK-style projects and legacy (pre-SDK) projects.4 Replies
You might try putting the CopyToOutputDirectory in the referenced project behind a variable that you explicitly unset in the other project (or a variable that when set changes the copy directive to not copy) ?
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Eh, yeah, was hoping there was something not so... hacky. I think that approach might cross the line beyond which the solution is worse than the original problem. :\ It would be easier to migrate the test project to use NLog's programmatic configuration API and stop relying on a physical config file so I could delete it, for example, but that also felt too involved.
Thanks, I didn't know about
ErrorOnDuplicatePublishOutputFiles
. Setting that to true
would be useful if I could eliminate the existing cases!Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.