尝试制定构建规则来创建 resx 文件的访问器类
我的 C++/CLI 项目中有 resources.resx 文件,并且想要创建一个构建来自动构建访问器类,以在需要时帮助访问资源。我已经搜索了很多,但还没有找到像样的解决方案(使用vs2010)。
我可以使用以下命令创建访问器类:
resgen /str:c++ resources.resx
这将创建一个 resources.h 文件(我想要的)和一个 resources.resources 文件(我可以删除的)。但我希望每当我更改 resources.resx 文件时都运行该命令,这让我有些头痛,因为该文件已经有一个构建目标“托管资源编译器”,并且当它在该文件上运行 resgen 时,它包括 7 个其他资源文件,并且没有 /str 开关。
到目前为止,唯一的自动解决方案是创建预构建事件命令,但这意味着每次构建时都要重新编译整个项目。
有什么建议吗?
I have resources.resx file in my C++/CLI project and want to create a build to to automatically build an accessor class to help access the resources when needed. I have searched a lot but haven't found a decent solution yet (using vs2010).
I can create the accessor class with this:
resgen /str:c++ resources.resx
This creates a resources.h file (which I want) and a resources.resources file (which I can delete). But I'd like to have the command being run whenever I change the resources.resx file and this gives me some headache as the file already has a build target, "Managed resource compiler", and while it runs resgen on that file, it includes 7 other resources files and doesn't have the /str switch.
The only automatic solution so far is to make a pre-build event command but that means recompiling the whole project every single time I make a build.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我这样解决了这个问题。在项目的预构建事件中,我插入了以下内容:
基本上,我创建一个新的 resources.h 并将其与现有文件进行比较。如果有任何差异,我会使用 type 复制文件以更新时间戳。这使得构建引擎仅在需要时更新 resources.h。不太漂亮,但它完成了工作。
I solved the issue like this. In the Pre-Build Event of the project I inserted this:
Basically, I create a new resources.h and compare it with the existing file. If there are any differences, I use type to copy the file in order to update the timestamp. This make the build engine only update resources.h when it is needed. Not pretty, but it gets the job done.