MSBuild中的PreBuildEvent和项目依赖项

时间:2012-06-14 01:56:53

标签: asp.net msbuild projects-and-solutions

我遇到了棘手的MSBuild问题。有一个包含多个网站的解决方案文件。每个网站都需要一个共同项目的MVC视图和其他网站内容的副本。该公共项目从共享组织空间复制文件。这是一个例子:


                          Site A
  OrgShared <- Common <-  Site B
                          Site C

文件副本通过.csproj文件的PreBuildEvent执行。问题是PreBuildEvent命令在检测到依赖项的构建事件被触发之前运行。所以这是事件的顺序:

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

问题发生在步骤1a。由于Common prebuild步骤尚未执行,因此站点A不会接收间接来自OrgShared的文件。

如何在不依赖网站A,B和B的情况下有效解决此依赖性问题? C必须直接从OrgShared复制?

1 个答案:

答案 0 :(得分:2)

想出来。在Common之前构建站点A的原因是由于.sln文件中的排序。更改解决方案中的顺序后,我能够首先在Common中运行PreBuildEvent。

在:

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

后:

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