battlmonstr
battlmonstr

Reputation: 6290

How to set up build dependencies of a code generation task?

I have 2 msbuild projects A and B in the same Visual Studio 2019 solution. A depends on B.

My goal is to set up a simple and intuitive incremental build with minimal boilerplate. If B source code is changed or the generated file is not found, that should trigger the code generation task to be re-run, and then rebuild A. (otherwise it should not re-run code generation)

The problem is that this works first time when the code is not generated yet, but on the 2nd change of B it bypasses the code generation step when A gets rebuilt. It simply says that A is "up-to-date".

B is an executable that I run inside the A's csproj with Exec like so:

  <Target Name="GenerateStuff" BeforeTargets="CoreCompile" 
    Inputs="$(SolutionDir)\B\bin\$(Configuration)\B.exe" 
    Outputs="$(ProjectDir)\Stuff.cs">
      <Exec Command="$(SolutionDir)\B\bin\$(Configuration)\B.exe" />
  </Target>

Thus for some reason it doesn't respect this "Inputs" as a valid trigger.

I'm also looking for more documentation and examples related to this.

Upvotes: 1

Views: 407

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100611

You should add the B.exe as an input to the project system so that the Visual Studio up-to-date check calls MSBuild when B.exe changes - this is an additional heuristic that VS runs before even calling MSBuild.

<ItemGroup>
  <UpToDateCheckInput Include="$(SolutionDir)\B\bin\$(Configuration)\B.exe" />
</ItemGroup>

Upvotes: 2

Related Questions