Reputation:
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:
Build Action
Content
Copy to Output Directory
Copy if newer
(Also tried with Copy Always
)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:
But they both have the same downsides:
This shouldn't be necessary! The fact this works under Rebuild suggests that this should work for Build too, but something is going wrong.
This is a manual change which the developer has to be aware of and action when adding a reference to Project B. Simply adding the project reference and having it all work is much less error prone.
Upvotes: 6
Views: 1486
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