views:

686

answers:

1

I've got a "Custom Tool" for Visual Studio to munge some template files into code. For consistency and portability I'd like to be able to run this template processor from MSBuild when building outside of Visual Studio.

Visual Studio creates the following snippets for the files:

<!-- the template -->
<None Include="Template.in">
  <Generator>Template Processor</Generator>
  <LastGenOutput>Template.in.Designer.cs</LastGenOutput>
</None>
<!-- generated file -->
<Compile Include="Template.in.Designer.cs">
  <AutoGen>True</AutoGen>
  <DesignTime>True</DesignTime>
  <DependentUpon>Template.in</DependentUpon>
</Compile>

The problem here is that the Template.in is only processed by the Studio, but not by MsBuild, which may lead to out-of-date Designer.cs files.

Is there a existing MSBuild task that can use the IVsSingleFileGenerator directly (including to load its location from the registry) or do I have to call the processor manually (either by implementing said MSBuild task myself or adapting the processor)?

Interestingly, the Using MSBuild article on the MSDN says:

Single file generators are accessible at design-time only, but MSBuild tasks can be used at design-time and build-time. For maximum flexibility, therefore, use MSBuild tasks to transform and generate code. For more information, see Project Items (Visual Studio SDK).


Update: I've hacked this specific custom tool into a msbuild task, but it's not pretty. I'd still prefer a well maintained generic solution. I've posted the source on my blog.

+1  A: 

When you specify your custom tool from within VisualStudio, what does it add to your project or solution files? Since they are just msbuild files, you might be able to use the added xml as a template for your own build files.

Pedro
good hint. I've added an example
David Schmitt