Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Studio's "Custom Tool" in MSBuild

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.

like image 376
David Schmitt Avatar asked Jan 12 '09 10:01

David Schmitt


People also ask

How do I add a custom tool in Visual Studio?

You can add custom tool options to the Visual Studio Property Pages window by creating an XML file. The Configuration Properties section of the Property Pages window displays setting groups known as rules.

What is the difference between MSBuild and Visual Studio build?

Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control. Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project.


1 Answers

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.

like image 174
Pedro Avatar answered Oct 20 '22 12:10

Pedro