Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSbuild build order issue - pre-build steps first or dependent projects first

Tags:

c#

msbuild

I have a project A depending on project B. Project A has some pre-build tasks that is dependent of some generated files from project B. When I build in Visual Studio, no problem. But when using MSBuild.exe, then there is problem because the build order is:

  • A's pre-build steps <- failed because B hasn't been compiled
  • B is compiled <- expected to be executed first
  • A is compiled

Is it the expected behaviour using MSBuild? Is there a way to tell MSBuild to do B first before A's prebuild steps?

I am using VS2010 C# and C++/CLI. I don't think if offeres additional info but here is how it is called:

Running process (C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBUILD.exe "..\..\..\dev\build\MyProj.sln" /t:Clean /p:Configuration=Release;Platform=Win32)
like image 303
M W Avatar asked Aug 27 '12 15:08

M W


1 Answers

Short answer

Remove your build event, and add something like the following to your project (.csproj):

<Target Name="AfterResolveReferences">
  <Exec Command="echo helloworld" />
</Target>

More info

You can read about customising the build process here: http://msdn.microsoft.com/en-us/library/ms366724%28v=vs.110%29.aspx

The Before Build event is fired before ResolveReferences, so if the project you reference has not already been built by the time it comes to your project's BeforeBuild event, then your BeforeBuild event will fail.

To overcome this, you should use a different entry point to customize the build process. In the above example, I use AfterResolveReferences, since this will ensure that all projects which you reference are already built.

like image 172
Jack Avatar answered Oct 11 '22 06:10

Jack