我想在构建解决方案之前使用 NAnt 修改 .h 文件中的字符串。
.h 文件中有一个宏:#define SERVER_ADDRESS "www.customserver.net",我想在部署软件之前修改该字符串,以便通过在命令行中传递地址来为自定义地址进行每个构建。
有谁知道如何做到这一点?
Thanks!
人们可以使用loadfile http://nant.sourceforge.net/release/latest/help/tasks/loadfile.html任务来帮助解决这个问题。此任务将给定文件加载到属性中。真正有用的是当你应用过滤链 http://nant.sourceforge.net/release/latest/help/types/filterchain.html with 替换令牌 http://nant.sourceforge.net/release/latest/help/filters/replacetokens.html替换文件的某些区域。例如,如果要定义一个类似模板的头文件看起来像这样:
#ifndef MyMacros_h
#define MyMacros_h
#define SERVER_ADDRESS "@SERVER_ADDRESS_TOKEN@"
#endif
可以使用 loadfile 任务将 @SERVER_ADDRESS_TOKEN@ 替换为任何字符串,然后使用echo http://nant.sourceforge.net/release/latest/help/tasks/echo.html实际编写的任务真实标题文件退出。
<loadfile file="MyMacrosTemplate.h" property="theMacrosFileContents">
<filterchain>
<replacetokens>
<token key="SERVER_ADDRESS_TOKEN" value="www.customerserver.net" />
</replacetokens>
</filterchain>
</loadfile>
<echo file="MyMacros.h" message="${theMacrosFileContents}" />
这将生成一个 MyMacros.h 文件,其中包含修改后的 SERVER_ADDRESS 字符串。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)