如何修改源恶性? [英] how to modify source with NAnt?

查看:144
本文介绍了如何修改源恶性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想构建解决方案之前修改字符串在.h文件楠。

I would like to modify the string in a .h file with NAnt before building the solution.

有一个在.h文件中的宏:#定义SERVER_ADDRESSwww.customserver.net,我想通过传递地址在命令行中部署软件,使每个构建可定制的地址发之前修改字符串。

There is a macro in .h file: #define SERVER_ADDRESS "www.customserver.net" and I would like to modify the string before deploying software so each build could be made for custom address by passing the address in command line.

有谁知道怎么可以这样做?

Does anyone know how this could be done?

谢谢!

推荐答案

人们可以使用的loadFile 任务,以帮助这一点。这个任务加载文件分成的属性。当您将的FilterChain ,提供的replacetokens 以替换该文件的某些区域。例如,如果一个人来定义的模板类的,看上去是这样的头文件:

One could use the loadfile task to help with this. This task loads the given file into a property. What is really useful is when you apply a filterchain with replacetokens to replace certain areas of the file. For example if one were to define a template-like header file that looked something like this:

#ifndef MyMacros_h
#define MyMacros_h

#define SERVER_ADDRESS "@SERVER_ADDRESS_TOKEN@"

#endif

人们可以使用的loadFile任务与任何字符串替换@ SERVER_ADDRESS_TOKEN @,然后使用的回声任务实际编写的真正的头的文件中退了出来。

One could the use the loadfile task to replace the @SERVER_ADDRESS_TOKEN@ with any string, and then use the echo task to actually write the real header file back out.

<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}" />

这将生成的SERVER_ADDRESS修改后的字符串MyMacros.h文件。

This will generate a MyMacros.h file with the modified string for the SERVER_ADDRESS.

这篇关于如何修改源恶性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆