挽星

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
修改一个工程生成的主文件的扩展名。

着实费了很大的劲,才搞出来,贴出来共享下,嘿嘿。

目的:一个工程,如果设置输出类型为class library,则编译链接后生成的主文件默认的扩展名为.dll。如果有需要要将扩展名改为其他,如.plugin,那么如何设置呢?

问题:在VS2008中,C#类型的工程的属性中并没有设置输出文件名称这一项。。。

解决:在Build Events标签的Pre-build events command line 和 Post-build event command line中分别如下设置:

    Pre-build event command line :if exist $(TargetName).plugin del $(TargetName).plugin
    Post-build event command line:ren $(TargetName)$(TargetExt) $(TargetName).plugin

说明:1)Pre-build event command line 和Post-build event command line真的非常有用非常灵活,它们分别提供了在编译链接前和编译链接后的用户接口,可以供用户方便的定制这两个时间段的操作。
2)Pre-build event command line 和Post-build event command line中的输入内容遵循DOS的语法规则——实际上,它们就是两个批处理文件。
3)可以看到有个Macros按钮,展开可以看到很多的宏,这些宏仅仅是一些提示,提供工程相关的对象的名称。
4)可以在编译时的OutPut窗口中看到Pre-build event command line 和Post-build event command line中批处理命令的执行语句,它们也确实是在当前工程编译之前和编译之后执行的。
5)if exist $(TargetName).plugin del $(TargetName).plugin:首先在编译前将之前可能存在的.plugin文件删除,如果不删除,编译后执行的重命名操作会报错(提示有一个重名文件存在);ren $(TargetName)$(TargetExt) $(TargetName).plugin完成后缀名的修改。其中,$(TargetName)就是通过Macros按钮的提示找到的宏,它的意思就是主输出文件的文件名,$(TargetExt)是默认的扩展名,这里面是.dll。

 

 

 

copy file

xcopy $(ProjectDir)XMLConfig $(SolutionDir)$(SolutionName)/$(OutDir) /S /E /C /Y

 

 

 

copy "$(TargetDir)$(TargetName).lib" ../lib/deploy/$(TargetName).lib
编译完成后将一个.lib 文件拷贝到指定目录

Post-Build Event command line

 

在vs2003 和2005中都支持了Build Events, 但是2003只支持单行的命令,而2005可以支持多行命令.

要想在2003中执行多行命令,只能把命令写在一个批处理文件中,然后通过调用批处理来执行.

1.在Solution explorer中用context meun查看project的property.

2.选择Build Events,可以看到Pre-build 和Post-build event command line,以及运行Post-build event 的条件

//——————————————————

用法收集

1.build完后修改build产物的名字(后缀),并覆盖已有的同名文件.

copy $(TargetFileName) $(TargetName).XXX y

2. 调用外部命令或批处理:

call "C:/Program Files/XXX.exe"

3. 条件判断:

IF NOT $(ConfigurationName) == Release GOTO end

    call "C:/Program Files/XXX.exe" $(ProjectDir)$(TargetName).cvp

:end

4.web project 自动部署

copy     $(TargetDir)*.*     //MyServer/MyService/bin
copy     $(ProjectDir)*.ascx     //MyServer/MyService

5. copy from one path to the other path

Copy "$(ProjectDir)pri.bin" "$(SolutionDir)$(SolutionName)/$(OutDir)"

copy  pri.bin(file name) from $(ProjectDir) to $(SolutionDir)$(SolutionName)/$(OutDir)

//——————————————————

Macro收集

$(DevEnvDir)

$(ProjectDir)

$(BuiltOuputPath)

$(ConfigurationName)

$(TargetName)  不含扩展名

$(TargetFileName)  包含扩展名

 转帖地址:http://blog.csdn.net/zhongjiekangping/article/details/5268249

posted on 2012-10-16 00:16  挽星  阅读(3376)  评论(0编辑  收藏  举报