title: How do I implicitly use a Target to generate an Included file?
body: <p>I'm a make(1) guy by nature.  What I want to do is the equivalent of this make fragment:</p>
  
  <pre><code>FILES = generated.cs
  
  app.exe : $(FILES)
      csc -out:$@ $(FILES)
  
  generated.cs :
      echo "// generated file" &gt; $@
  </code></pre>
  
  <p>That is, <code>$(FILES)</code> contains a list of files, some of which may be generated by other targets within the Makefile.  This Just Works.</p>
  
  <p>I would like to do the ~same thing with MSBuild.  Unfortunately, my attempt has failed:</p>
  
  <pre><code>&lt;Target Name="BuildGenerated"
      Outputs="Generated.cs"
      &gt;
    &lt;WriteLinesToFile
      File="Generated.cs"
      Lines="// generated file"
      Overwrite="True"
      /&gt;
  &lt;/Target&gt;
  &lt;ItemGroup&gt;
    &lt;Compile Include="Generated.cs" /&gt;
  &lt;/ItemGroup&gt;
  </code></pre>
  
  <p>That is, use <code>&lt;Compile/&gt;</code> to include a generated file and have MSBuild deduce that since <code>Generated.cs</code> doesn't exist, it should find some <code>&lt;Target/&gt;</code> which will generate that file and then execute it.</p>
  
  <p>It looks like the only way to do something like this is to add pre-build steps, but that seems like a hack.  Are pre-build steps the only way to do this?  Or is there some way to make MSBuild act like it has a brain?</p>
  
  <p><strong>Update 1</strong>: For reference, this would be the pre-build incantation needed to make it work, and (again) this is something I'd rather avoid if possible:</p>
  
  <pre><code>&lt;PropertyGroup&gt;
    &lt;CompileDependsOn&gt;
      BuildGenerated;$(CompileDependsOn)
    &lt;/CompileDependsOn&gt;
  &lt;/PropertyGroup&gt;
  </code></pre>
  
  <p>This would need to occur <em>after</em> the <code>&lt;Import Project="..." /&gt;</code> element(s) defining <code>&lt;CompileDependsOn/&gt;</code>.</p>