The 10,000th Why won't my MSBuild task run post

Visual Studio 19

So, I'm trying to get a custom task to work in Visual Studio. I can get this to work with a custom build tool, but that's not viable because (for really stupid reason) you cannot indicate a build target for a custom build tool that I can see. There's only a project level build target and all custom steps and tools use the same one. So if you also need custom build steps on other targets that's not workable.

I'm on 2019. Here is what I have (one of an ~infinite set of variations I've tried)

    <Target Name="SpidlGen" BeforeTargets="BeforeBuild"
            Inputs="$(ProjectDir)SpidlGen_Gen.Spidl"
            Outputs="$(ProjectDir)SpidlGen_Gen.cpp;$(ProjectDir)SpidlGen_Gen.h">
      <Message Text="Spidl File Generation" Importance="High"/>
      <Exec Command="$(SolutionDir)Tools\Spidl.exe $(ProjectDir)SpidlGen_Gen.Spidl $(ProjectDir)SpidlGen_Gen.cpp $(ProjectDir)SpidlGen_Gen.h"/>
    </Target>
   <ItemGroup>
      <None Include="SpidlGen_Gen.spidl"/>
  </ItemGroup>

I have the inputs and outputs correct. I have a high priority message so I can see if it's run. It never runs, ever. I can change the source or delete the output files altogether and it never gets invoked.

Am I missing something obvious? I looked through all the log files and there's nothing there that at all indicates it even tried or evaluated this target.

It really just shouldn't be this hard to add the invocation of a tool to the build process. I've been at this now for a full work day and have achieved nothing but a real dislike of this tool.

Posted May 18, 2020, 3:09 PM UTC · edited

03
Full-SpectralOP•

OK, after more experimentation driving it temporarily from the command line, where I can see what targets are being invoked, I see more of what is going on.

This is a code generator. So it's spitting out a cpp and h file. If those files are deleted, the target isn't being invoked so the file don't get generated. It just goes straight to trying to compile and fails because the files aren't there.

If the files do exist, I can get the generator to run, but the check to see if anything needs to be compiled is clearly being done before that, so it doesn't actually try to rebuild the files until the next build invocation.

So basically what I'm trying to do is:

  1. Invoke the code generator if the targets are out of date or do not exist
  2. Make sure that the generated files and files that depend on the generated files are checked for need to build after #1 completes.

I just cannot seem to get that these things to work. And, inevitably as I try to get these to work, I break the working scenarios, because this system is just so twitchy.

1
Full-SpectralOP•

Ughh... It looks like the issue is something about Visual Studio. I think I've probably had it 'right' a hundred times but it doesn't act the same in the IDE as it does from the command line.

I just removed the inputs and outputs since the tool checks that anyway, so it's fine to just always run it. On the command line I've got it now always rebuilding as it should, and at the right place. In the IDE it will generally only ever run the tool after I reload the project. After that it never generally runs it again.

Is there something I'm missing about the two means of invocation? Clearly it's doing the right thing on the command line, so I would think I have it right.

1
Full-SpectralOP•

Some more reading seems to imply that the IDE does its own 'is everything up to date' check and won't even invoke MSBuild if it thinks so. That's fine for a lot of things, but not for a code generator which may need to change files.

I guess it deals correctly with custom build tools (which does work) because that's a VS UI configured thing, but hand built targets apparently not.

Is that the case? If so I'm really disgusted that I just wasted a day and a half on that.

1