Friday, October 31, 2008

How to perform resgen in VS post-build command

In my VS 2008 projects, I need to generate resource file from .resx file after each build (in case there were changes on the .resx file). Of cource I can do it manually but it is just not efficient at all.

To solve this, it is simple, go to project's properties page, at Build Events's post-build command box, type this:

"$(VS80COMNTOOLS)..\..\SDK\v2.0\Bin\resgen.exe" "{ResourceDirectory}\{ResourceName}.resx" "{OutputDirectory}\{ResourceName}.resources"

For example:
"$(VS80COMNTOOLS)..\..\SDK\v2.0\Bin\resgen.exe" "$(ProjectDir)Resource\MyResource.resx" "$(OutDir)Resources\MyResource.resources"

Remember to put the quote " in the parameter. At the very first time, I do not realize the quotes are needed, and always get error "The command $(VS80COMNTOOLS)..\..\SDK\v2.0\Bin\resgen.exe {ResourceDirectory}\{ResourceName}.resx {OutputDirectory}\{ResourceName}.resources" failed and exited with code 9009.

Hope this helps.

No comments: