Using Studio's “Custom Tool” in MSBuild

元气小坏坏 提交于 2019-12-22 03:49:02

问题


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:


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.



来源:https://stackoverflow.com/questions/435037/using-studios-custom-tool-in-msbuild

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!