2

I have an msbuild target that invokes external generator and has to be always executed on solution rebuild even if project that contains this target was not modified.

I have tried appending to $(BuildDependsOn) but it is only executed if project was modified.

Essentially I have to extend mechanism that msbuild uses to check whether project was modified to plug my own check.

Marcin Wisnicki
  • 4,511
  • 4
  • 35
  • 57
  • you should probably post what your target/project file look like. Normally a rebuild cleans all projects, modified or not, and rebuilds them? – stijn Jul 22 '13 at 17:41
  • possible duplicate of [Visual Studio 2012 - MSBuild incremental build not detecting changes](http://stackoverflow.com/questions/13138820/visual-studio-2012-msbuild-incremental-build-not-detecting-changes) – Marcin Wisnicki Jul 23 '13 at 12:25
  • if that is the solution, you can just delete your question as well (I think) – stijn Jul 24 '13 at 06:55

1 Answers1

1

I guess you tried do it this way:

<Target Name="MyCustomBeforeBuild" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="@(Compile->'%(RecursiveDir)%(Filename)%(Extension).generated')">
    <Message Text="MyCustomBeforeBuild Begin" Importance="High" />
    <Copy SourceFiles="@(Compile)" DestinationFiles="@(Compile->'%(RecursiveDir)%(Filename)%(Extension).generated')" />
    <Message Text="MyCustomBeforeBuild End" Importance="High" />
</Target>

In this case MSBuild will use incremental build and evaluates that no file were modified based on timestamp comparison of input and output files.

In this case you can see in detailed or in diagnostic log message like this

Skipping target "MyCustomBeforeBuild" because all output files are up-to-date with respect to the input files.

But by specifying “fake outputs” (see .fake in Outputs attribute of Target) you can force MSBuild execute it every time (because fake file does not exist, no timestamp comparison will happen so it is always executed).

<Target Name="MyCustomBeforeBuild" BeforeTargets="BeforeBuild" Inputs="@(Compile)" Outputs="@(Compile->'%(RecursiveDir)%(Filename)%(Extension).generated.fake')">
    <Message Text="MyCustomBeforeBuild Begin" Importance="High" />
    <Copy SourceFiles="@(Compile)" DestinationFiles="@(Compile->'%(RecursiveDir)%(Filename)%(Extension).generated')" />
    <Message Text="MyCustomBeforeBuild End" Importance="High" />
</Target>
Palo Misik
  • 741
  • 3
  • 7
  • 1
    `BeforeBuild` doesn't seem to work in VS2012, use `BeforeTargets=...`, see http://stackoverflow.com/questions/13727351/what-happened-to-beforebuild-and-other-targets-in-vs2012 – stijn Jul 23 '13 at 06:49
  • I have tried this approach but it doesn't work. I've also tried adding InitialTargets with same result. It seems like Visual Studio is not even invoking msbuild on this project. – Marcin Wisnicki Jul 23 '13 at 12:15
  • 1
    And the solution can be found [here](http://stackoverflow.com/a/13414681/443422). – Marcin Wisnicki Jul 23 '13 at 12:23