我们使用 PublicResXFileCodeGenerator
从 *.resx
文件生成 *.Designer.cs
文件。 目前,只要保存 .resx
或右键单击并选择“运行自定义工具”,就会生成这些文件。
我希望能够在构建时自动运行该工具,而不必手动执行。 Designer.cs 文件不受源代码控制,因此每次其他人更改资源或第一次签出时都必须手动生成它们会很烦人。 如果文件在每次构建时都生成也没关系,因为它们不是很大,但仅在它们过时时才生成会更酷。
注意:这将是 Visual Studio 构建的一部分,而不是命令行构建。 我找到了另一个问题的答案,说可以从 VS 内部,而不是命令行: 在构建时运行 Visual Studio 自定义工具
We are using PublicResXFileCodeGenerator
to generate *.Designer.cs
files from *.resx
files. Currently these are generated whenever the .resx
is saved or when we right click and choose "Run Custom Tool".
I want to be able to run this tool automatically at build time, rather than having to do it manually. The Designer.cs
files are not kept under source control, so it gets annoying to have to manually generate them every time someone else changes the resource, or on the first checkout. It's all right if the files are generated on every build, since they aren't very large, but doing it only when they're out of date would be even cooler.
Note: This would be part of a Visual Studio build, not a command line build. I found an answer to another question saying that it is possible from within VS, just not command line: Run a Visual Studio custom tool at build time
发布评论
评论(1)
您可以编写一个 VS 宏,在需要时简单地运行自定义工具。 自动化方法是 VSProjectItem.RunCustomTool。 看看这个关于类似问题的答案:为整个解决方案运行自定义工具< /a>
否则,
PublicResXFileCodeGenerator
只是 StronglyTypedResourceBuilder 类,您可以按照自己想要的方式实现自动化。 我不知道它上面是否有一个 Msbuild 任务,但您也可以编写一个,或者您可以在预构建步骤中编写一个自定义程序。 以下是如何使用此类的示例: ASP.NET 中的强类型资源You could write a VS Macro that simply runs the custom tool when you need it. The automation method is VSProjectItem.RunCustomTool. Have a look at this answer on SO for a similar problem: Run Custom Tool for entire solution
Otherwise,
PublicResXFileCodeGenerator
is just a VS wrapper on the StronglyTypedResourceBuilder Class, that you can automate the way you want. I don't know if there is an Msbuild Task on top of it, but you also could write one, or you can just write a custom program in a pre build step. Here is an example on how to use this class: Strongly typed resources in ASP.NET