title: Make VisualStudio run a command to generate C# code
body: <p>I'm trying to do something extremely simple, yet despite hours of scouring the Internet and desperately typing in every tiny example fragment I can find, I literally <strong>cannot</strong> make VS do what I want. Seriously frustrated here!</p>
  
  <p>This is what I want:</p>
  
  <ul>
  <li>When I do a build, I want VS to find every <code>*.fubar</code> file in the project.</li>
  <li>For each <code>*.fubar</code> file, I want VS to execute <code>fubar.exe</code> with the input file as argument.</li>
  <li>I want VS to compile the resulting <code>*.cs</code> files as usual.</li>
  </ul>
  
  <p>I am damn-well <em>convinced</em> it must be possible to achieve this trivially simple task. I just need to figure out how.</p>
  
  <hr>
  
  <p>So that's the problem. Let me explain what I've researched so far.</p>
  
  <p>It seems that you can write a VS extension by implementing some COM interface. But that requires you to <em>edit the Registry</em> to tell VS where the plugin is. Obviously that's completely unacceptable; I should <em>not</em> have to reconfigure the OS just to run a command-line tool!</p>
  
  <p>It appears that MSBuild is supposed to be this ultra-configurable build management tool where you can define an arbitrary set of build steps and their interdependencies. It seems like it <em>should</em> be trivial to add an extra task before the build C# compilation step that runs <code>fubar.exe</code> to generate the source code. And yet, after hours of trying, I cannot get a single C# file to appear.</p>
  
  <p>Some documents talk about special pre-build and post-build steps. But it seems silly to need a special hook when the number and order of build steps is supposed to be arbitrary to begin with. Regardless, I tried it, and it still didn't work.</p>
  
  <p>To be clear: Playing around with the project file makes VS display the item properties slightly differently, and doesn't make the build fail. But it also doesn't ever make any C# files appear. (At least, I can't find them anywhere on the disk. I can't tell if my tool is actually being run or not &mdash; I suspect "not".)</p>
  
  <p>Can <em>anybody</em> tell me how to make this trivial, trivial thing work? There <em>must</em> be a way!</p>