user310988
user310988

Reputation:

Visual Studio copies "Content" files from dependency projects on Rebuild, but not on Build

I have a solution with two projects:

Project A references Project B via a project dependency.
Project B contains a folder, and in this folder are some files.

The properties of these files are set to:

When I Build Project B, the files in the content folder are copied to the output folder for Project B.
e.g. ProjectB/bin/debug/contentfolder/files

When I Rebuild Project A, the files in the content folder are copied to the output folder for Project A.
e.g. ProjectA/bin/debug/contentfolder/files

When I Build Project A, the files in the content folder are not copied to the output folder for Project A.
e.g. ProjectA/bin/debug/contentfolder/NO FILES HERE


I could understand if Visual Studio "can't see" the files in dependency projects for some reason, and the files were never copied to ProjectA's output.

But that's not the case since it works during a rebuild.

So it feels like either I'm doing something wrong, and not noticing, or that Visual Studio is doing something wrong, and needs fixing.

I found this question which is similar to mine: Visual Studio Build vs Rebuild: Why are my DLLs only sometimes being copied into the output directory?

However it doesn't have any answers, and it's not a duplicate as I'm more explicit about my solution layout and the circumstances under which this behavior occurs.

There is an older question, with an accepted answer here: Why the native DLL is not copied to the output directory

But it says:
(NOTE: Their usage of Project A/B is opposite to mine.)

If a C# project B has direct reference to project A, VS will copy all dependent files used by project A to the output directory of project B.

Which is clearly not happening in my case, which is the basis of my question!


There are two work-arounds that seem obvious to me:

  1. The Content folder and files can be added to the console project.
  2. A post-build event can be used to copy the files after the console project has finished building.

But they both have the same downsides:

Upvotes: 6

Views: 1486

Answers (1)

Tariktiri
Tariktiri

Reputation: 149

I had similar problem - had content (connections.config in my case) which was copied to 2 projects - both projects copied files on rebuild, but one them did not copy it on build.

I've added a reference to the source project itself and now it works just fine, i assume that on build when the project does not have refernece does not see the projects details, while on "rebuild all" it does.

Upvotes: 1

Related Questions