Building a project file with the Microsoft.Build.BuildEngine
library seems to be ignoring the BeforeTargets
attribute.
My project file has the following target:
<Target Name="MyTestTarget" BeforeTargets="Build">
<Message Importance="High" Text="Running MyTestTarget" />
</Target>
and when I compile it with the following code (F#, but does the same in C#):
open System
open Microsoft.Build.BuildEngine
open Microsoft.Build.Framework
[<EntryPoint; STAThread>]
let main argv =
let engine = new Engine()
engine.RegisterLogger(new ConsoleLogger())
let project = new Project(engine)
project.Load("MyProjectFile.fsproj")
let succeeded = engine.BuildProject(project, "Build")
0
the target "MyTestTarget"
is not run. Note that when I use MSBuild.exe
4.0 instead, "MyTestTarget"
is correctly run.
I know that BeforeTargets was added in MSBuild 4.0, and would throw an exception if used with an older version of Microsoft.Build
. But I haven't found anything about BeforeTargets being ignored by MSBuild 4.