当前位置:   article > 正文

VS2005得include,library,src等路径自动设置_vs2005命令行怎么修改路径

vs2005命令行怎么修改路径

一般更改 VS2005 路径都是通过打开 VS2005 ,然后选择 ”Tool”, “Options”, “Projects and Solutions”, “VC++ Directories”, 然后手动添加或删除 include, library, source 路径。

当经常需要批量更改路径时,以上手动步骤就太繁琐,太麻烦了。其实 VS2005 把这些路径设置存在 CurrentSettings.vssettings 文件中。这个文件通常放在 My Documents/Visual Studio 2005/Settings 下。

可以以文本方式打开文件,可以看到它是一个 xml 格式,查找如下路径可以找到 include, library, source 的设置:

---------------------------------------------------------------------------------------

< UserSettings >

< ToolsOptions >

< ToolsOptionsSubCategory name =" VCDirectories " …… >

< PropertyValue name =" IncludeDirectories "> …</ PropertyValue >

< PropertyValue name =" LibraryDirectories "> …</ PropertyValue >

< PropertyValue name =" SourceDirectories "> …</ PropertyValue >

---------------------------------------------------------------------------------------

把里面的内容整理一下,显示如下:

---------------------------------------------------------------------------------------

Win32

|

$(VCInstallDir)lib;

$(VCInstallDir)atlmfc/lib;

$(VCInstallDir)atlmfc/lib/i386;

$(VCInstallDir)PlatformSDK/lib;

$(FrameworkSDKDir)lib;

$(VSInstallDir);

$(VSInstallDir)lib;

D:/works/ACE/ACE_wrappers/lib;

D:/local_vap/VAPLib;

D:/local_vap/MsXml3/lib;

D:/local_vap/Adfin/lib/mrv

|

Pocket PC 2003 (ARMV4)

|

$(VSInstallDir)SmartDevices/SDK/PocketPC2003/lib/ARMV4;

$(VCInstallDir)ce/atlmfc/lib/ARMV4;

$(VCInstallDir)ce/lib/ARMV4;

|

Smartphone 2003 (ARMV4)

|

$(VSInstallDir)SmartDevices/SDK/SmartPhone2003/lib/ARMV4;

$(VCInstallDir)ce/atlmfc/lib/ARMV4;

$(VCInstallDir)ce/lib/ARMV4;

---------------------------------------------------------------------------------------

可以看到他以 | 分隔开了不同的小块,其中第二个小块就是我们在 VC 中的 include 设置路径,前面几条是 VC 默认的,后面以 D: 开头的就是个人后面添加的。手动改变这些字符就可以达到通过 VC 更改同样的效果。

 

在这里,我通过 perl dos 的批处理自动进行 include, library, src 路径的自动改变。

首先,创建一个文本文件,填入我们需要的路径设置:

My_vc_path.txt :

---------------------------------------------------------------------------------------

library=

D:/works/ACE/ACE_wrappers/lib;

D:/local_vap/VAPLib;

D:/local_vap/MsXml3/lib;

D:/local_vap/Adfin/lib/mrv;

 

include=

D:/works/ACE/ACE_wrappers;

D:/local_vap/VAPInclude;

D:/local_vap/Adfin/include/mrv;

D:/local_vap/MsXml3/inc;

 

src=

D:/works/ACE/ACE_wrappers/ace;

D:/works/dev_net/library/vaabase/trunk/Source Code;

---------------------------------------------------------------------------------------

然后是 perl 文件,他的主要功能就是打开 My_vc_path.txt ,读入设置,然后再打开 CurrentSettings.vssettings ,查找相应路径并进行替换。这里要注意不要把 VC 默认的路径给替换了。

Perl 程序代码:

vc_path_change.pl :

---------------------------------------------------------------------------------------

if (@ARGV < 2)

{

      die ('usage : "vssettings file name" "your file name"');

}

 

$vc_path = @ARGV[0];

$my_vc_path = @ARGV[1];

$vsseeting_text = "";

@my_setting_lines = ();

 

if (! open (VC_PATH, $vc_path))

{

      die ("can not open /"$vc_path/"");

}

else

{# 读入 CurrentSettings.vssettings 文件内容,并存入 $vsseeting_text

      @tmpLines = <VC_PATH>;

      $vsseeting_text = join (" ", @tmpLines);

     

      close (VC_PATH);

}

 

if (! open (MY_VC_PATH, $my_vc_path))

{

      die ("can not open /"$my_vc_path/"");

}

else

{

      @my_setting_lines = <MY_VC_PATH>;

      chop (@my_setting_lines);

      close (MY_VC_PATH);

}

 

@my_settings = ();

{# 解析获取自己的 include, lib, src 设置

      @my_vc_path_para = ("include=", "library=", "src=");

      $para_index = 0;

      foreach $line (@my_setting_lines)

      {

           $math_para = 0;

           for ($index=0; $index<3; ++$index)

           {

                 if ($line =~ $my_vc_path_para[$index])

                 {

                      $math_para = 1;

                      $para_index = $index;

                 }

           }

          

           if ($math_para == 0)

           {

                 $my_settings[$para_index] .= $line;

           }

      }

     

      for ($index=0; $index<3; ++$index)

      {

           print ("$my_vc_path_para[$index]" . $my_settings[$index], "/n");

      }

}

 

 

 

{# 替换路径

      @str_header = ('<PropertyValue name="IncludeDirectories">',

                                             '<PropertyValue name="LibraryDirectories">',

                                             '<PropertyValue name="SourceDirectories">');

      $str_ender = '</PropertyValue>';

     

      for ($index=0; $index<3; ++$index)

      {

           #<PropertyValue name="IncludeDirectories"> …</PropertyValue>

           $pattern = "(.*$str_header[$index])(.+?)($str_ender.*)";

           @list1 = $vsseeting_text =~ /(.*$str_header[$index])(.+?)($str_ender.*)/s;

           print ("Fetch full path : $list1[1]/n");

                

           #Win32|$(VCInstallDir)include;...|...

           @list2 = $list1[1] =~ /^(.*?/|)(.+?)(/|.*)/s;

           print ("Fetch path : $list2[1]/n");

          

           #$(VCInstallDir)include;...D:/local_vap/SSL/include;

           @system_path = $list2[1] =~ /(/$.+?;)/g;

           $list2[1] = join ("", @system_path) . $my_settings[$index];

           print ("New path = $list2[1]", "/n");

          

           $list1[1] = join ("", @list2);

           $vsseeting_text = join ("", @list1);

      }

}

 

if (! open (VC_PATH, ">" . $vc_path))

{

      die ("can not open /"$out_path/"");

}

else

{

      print VC_PATH ($vsseeting_text);

      close (VC_PATH);

}

---------------------------------------------------------------------------------------

 

由于 perl 程序需要两个参数,一个是 CurrentSettings.vssettings 文件的路径,另一个是自己的设置文件,所以再写个 cmd 文件。

---------------------------------------------------------------------------------------

set vssetting_file=C:/Documents and Settings/Jiqin.Hong/My Documents/Visual Studio 2005/Settings/CurrentSettings.vssettings

set my_file=./my_vc_path_1.txt

perl vc_path_change.pl "%vssetting_file%" "%my_file%"

---------------------------------------------------------------------------------------

 

好,到此完成,每次需要更改 VC include, library, src 等路径时,创建好文本路径文件,填入设置,然后运行 cmd 文件即可。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/292892
推荐阅读
相关标签
  

闽ICP备14008679号