Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running PublicResXFileCodeGenerator at compile time

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

like image 706
Tim Avatar asked Jun 24 '09 15:06

Tim


1 Answers

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

like image 65
Simon Mourier Avatar answered Sep 28 '22 07:09

Simon Mourier