在构建时运行Visual Studio自定义工具 [英] Run a Visual Studio custom tool at build time

查看:192
本文介绍了在构建时运行Visual Studio自定义工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,可以将文本文件转换为资源文件,这样我就可以通过将用于不同语言的文本文件转换为不同的资源来获得多种语言支持.一旦运行脚本以获取resx文件,就必须运行自定义构建工具(如下所述:

I have a script that will convert a text file into a resource file, so that I can have multiple language support by having text files for different languages converted into different resources. Once I run the script to get the resx file, I then have to run a custom build tool (as described here:Link to Code Project) in order to create the Designer.cs files to use the new files.

按照我应该能够通过单击一个按钮来构建整个项目的原则,我该如何删除必须显式调用自定义构建工具才能生成代码隐藏文件的步骤?

In keeping with the philosophy that I should be able to build the entire project with a single button click, how can I remove the step where I have to explicitly call the custom build tool in order to make the codebehind files?

我尝试过自动删除Designer.cs文件作为预构建步骤,因为如果没有Designer.cs文件但没有骰子,我认为自定义构建工具将自动运行.

I've tried automatically deleting the Designer.cs files as a pre-build step, since I would think that the custom build tool would automatically run if there were no Designer.cs files, but no dice.

因此,我希望我的Visual Studio/msbuild中的生成脚本可以执行以下操作: 1)将文本转换为resx(完成) 2)将resx文件移动到适当的目录(完成) 3)使用自定义构建工具创建designer.cs文件(未完成)

So, I want my build script in Visual Studio/msbuild to do: 1) convert text to resx (done) 2) move resx files to appropriate directory (done) 3) create designer.cs files using a custom build tool (not done)

这是最后一步...

推荐答案

不幸的是,我认为没有简单的方法可以做到这一点.自定义生成工具只能在VS.NET中运行-当您从命令行使用MSBuild生成项目时,它们不会运行.

Unfortunately I don't think there's an easy way of doing this. Custom Build Tools only run from within VS.NET - they don't run when you build your project using MSBuild from the command line.

通常,如果您可以选择将构建工具编写为客户构建工具或MSBuild任务,则每次都选择MSBuild任务,因为这些任务将在VS.NET和命令行中运行.

In general, if you have the choice of writing a build tool as a Customer Build Tool or an MSBuild Task then choose the MSBuild Task every time as these Tasks will run in VS.NET and from the command line.

存在用于资源的designer.cs文件,以支持您的编码.它们为您提供了对资源文件的强类型访问.因此,只要您在VS.NET中创建区域性不变资源(并让它创建.designer.cs文件),然后在以后添加其他语言支持(其他.resx文件)就可以正常工作.

The designer.cs files for resources are there to support your coding. They give you the strongly typed access into the resource file. So, as long as you create your culture invariant resources in VS.NET (and let it create the .designer.cs files) then adding additional language support later (additional .resx files) should work fine.

但是,如果您的文本文件是您的主要资源文件,并且首先要在这些文本文件中添加新的资源字符串,那么您将需要找到另一种生成.cs文件的方式,该文件可用于对这些资源.如果您愿意,自己生成一个(.designer.cs)文件(或类似的文件)就不会那么困难了.使用CodeDom或T4,您可以使用现有的.designer.cs文件作为模板来创建帮助器类.

If, however, your text files are your primary resource files, and you're adding new resource strings into these text files first, then you'll need to find another way of generating .cs files that allow you to code against those resources. If you HAD to, generating the .designer.cs file yourself (or somethign similar) wouldn't be that difficult. Using CodeDom or T4 you could create the helper class, using an existing .designer.cs file as a template.

这篇关于在构建时运行Visual Studio自定义工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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