I'm having a tricky MSBuild issue. There is a solution file containing multiple web sites. Each web site needs a copy of MVC views and other web site content from a common project. That common project copies files from a shared organizational space. Here's an illustration:
Site A OrgShared <- Common <- Site B Site C
File copies are performed through the PreBuildEvent of the .csproj
files. The problem is that the PreBuildEvent commands run before detected dependencies' build events are fired. So here's the sequence of events:
1. Site A is build a. Prebuild step is executed (copy files from Common) b. Common is built i. Prebuild step is executed (copy files from OrgShared) ii. Build & postbuild is executed c. Build & postbuild are executed 2. Site B is built a. Prebuild step is executed (copy files from Common) b. Build & postbuild are executed
The problem occurs at step 1a. Because the Common prebuild step has not yet executed, Site A does not receive the files that indirectly come from OrgShared.
How can I effectively resolve this dependency issue without relying on sites A, B & C having to copy directly from OrgShared?
Figured it out. The reason why Site A was being built before Common was because of the ordering in the .sln
file. After changing the ordering in the solution, I was able to have the PreBuildEvent run in Common first.
Before:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site A", "SiteA.csproj", "{6E7FAE47-74A6-4740-9AC5-9599E850E834}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common.csproj", "{C510B337-7459-4494-BBCB-B79FECD2AA66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site B", "SiteB.csproj", "{F3CAFCE9-A96D-4EE5-BE09-420E27344345}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site C", "SiteC.csproj", "{A50C5DE2-4846-40F2-86B1-B103F413DE0F}"
EndProject
After:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Common", "Common.csproj", "{C510B337-7459-4494-BBCB-B79FECD2AA66}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site A", "SiteA.csproj", "{6E7FAE47-74A6-4740-9AC5-9599E850E834}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site B", "SiteB.csproj", "{F3CAFCE9-A96D-4EE5-BE09-420E27344345}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Site C", "SiteC.csproj", "{A50C5DE2-4846-40F2-86B1-B103F413DE0F}"
EndProject