© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
5 replies
distilld

❔ How can I prevent content files from ProjectReferences being copied on build?

I have a test project (
Tests.csproj
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
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
CopyToOutputDirectory
set to
PreserveNewest
PreserveNewest
.

When I build
Tests.csproj
Tests.csproj
and inspect the resulting
msbuild.binlog
msbuild.binlog
file, I see double writes for
Tests\bin\Release\nlog.config
Tests\bin\Release\nlog.config
. I suspect/hope this is due to
App.csproj
App.csproj
's nlog.config being copied into
Tests\bin\Release
Tests\bin\Release
, and then
Tests.csproj
Tests.csproj
's nlog.config being copied and overwriting it.

With NuGet package references I can control this with
<ExcludeAssets>contentfiles</ExcludeAssets>
<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.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to prevent code from being leaked?
C#CC# / help
3y ago
How do I prevent my app from being terminated from user & other apps?
C#CC# / help
4y ago
✅ Prevent WPF applications from being detected as a virus
C#CC# / help
3y ago
How to prevent GitHub from building executables for all platforms?
C#CC# / help
2y ago