使用Studio的“自定义工具"在MSBuild中 [英] Using Studio's "Custom Tool" in MSBuild

查看:86
本文介绍了使用Studio的“自定义工具"在MSBuild中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于Visual Studio的自定义工具",可以将一些模板文件压缩为代码.为了保持一致性和可移植性,我希望能够在Visual Studio外部进行构建时从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为文件创建以下片段:

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>

这里的问题是Template.in仅由Studio处理,而不由MsBuild处理,这可能会导致过时的Designer.cs文件.

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.

是否存在可以直接使用IVsSingleFileGenerator的现有MSBuild任务(包括从注册表中加载其位置),还是我必须手动调用处理器(通过自己实施上述MSBuild任务或调整处理器)?

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)?

有趣的是,MSDN上的使用MSBuild 文章说:

Interestingly, the Using MSBuild article on the MSDN says:

可以访问单个文件生成器 仅在设计时,但MSBuild任务 可以在设计时使用 建立时间.为了获得最大的灵活性, 因此,使用MSBuild任务来 转换并生成代码.欲了解更多 信息,请参阅项目项(可视 Studio SDK).

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).


更新:我已经将此特定的自定义工具入侵了msbuild任务,但这并不漂亮.我仍然希望维护良好的通用解决方案.我在我的博客上发布了源文件.


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.

推荐答案

在Visual Studio中指定自定义工具时,它将对您的项目或解决方案文件添加什么?由于它们只是msbuild文件,因此您可以使用添加的xml作为自己的构建文件的模板.

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.

这篇关于使用Studio的“自定义工具"在MSBuild中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆