2010-03-01 193 views
1

我正在尝试一些VS2005 IDE宏来修改解决方案中的大量项目(〜80)。我希望设置的一些属性会将程序化界面暴露给“默认”,但其他许多属性却不会。有没有一种通用的方法来将这些属性设置为默认值? (最终意味着从.vcproj文件进行删除)将VCProject属性设置为默认值

简单的例子,设置一些随机属性:

Sub SetSomeProps() 
    Dim prj As VCProject 
    Dim cfg As VCConfiguration 
    Dim toolCompiler As VCCLCompilerTool 
    Dim toolLinker As VCLinkerTool 
    Dim EnvPrj As EnvDTE.Project 

    For Each EnvPrj In DTE.Solution.Projects 
     prj = EnvPrj.Object 
     cfg = prj.Configurations.Item(1) 


     toolLinker = cfg.Tools("VCLinkerTool") 

     If toolLinker IsNot Nothing Then 
      ' Some tool props that expose a *default* interface' 
      toolLinker.EnableCOMDATFolding = optFoldingType.optFoldingDefault 
      toolLinker.OptimizeReferences = optRefType.optReferencesDefault 
      toolLinker.OptimizeForWindows98 = optWin98Type.optWin98Default 
     End If 

     toolCompiler = cfg.Tools("VCCLCompilerTool") 

     If toolCompiler IsNot Nothing Then 
      ' How to set it to default? (*erase* the property from the .vcproj)' 
      toolCompiler.CallingConvention = callingConventionOption.callConventionCDecl 
      toolCompiler.WholeProgramOptimization = False 
      toolCompiler.Detect64BitPortabilityProblems = False 
     End If 

    Next 

End Sub 

任何意见,将不胜感激。

回答

2

对于VS 2005,我相信你可以在VCConfiguration上使用ClearToolProperty方法。下面的代码将做到这一点的CallingConvention(这是C#,但我对VB确保类似的事情的作品):

cfg.ClearToolProperty(toolCompiler, "CallingConvention"); 

这将对作为进入GUI和此选项选择"<inherit from parent or project defaults>"同样的效果。

不幸的是,这似乎在VS 2010中被弃用,我不确定新支持的方法是什么。

+1

对于VS2010,[此论坛帖子](http://social.msdn.microsoft.com/Forums/en-IE/vsx/thread/8dff2053-432f-4bdd-b668-3c88960e1409)建议您可以投射工具对象添加到新的[IVCRulePropertyStorage](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.vcprojectengine.ivcrulepropertystorage.aspx)接口,然后使用其DeleteProperty方法摆脱该属性。尽管如此,我还是无法自己尝试。 – 2013-01-22 23:41:08