我使用Visual Commander(从https://vlasovstudio.com/visual-commander/)将一些宏用于操作VS2010中的C++项目到VS2015。事情似乎工作确定(我可以通过配置接入解决方案,创造VCProjects,循环等),但我有一个问题 - 这曾在VS2010电话:在VS2015宏中找不到VCCLCompilerTool(使用Visual Commander)
cfg.Tools("VCCLCompilerTool")
...在VS2015失败,与“System.MissingMemberException:找不到类型为'VCCollectionShim'的默认成员”。错误,表明该集合没有“VCCLCompilerTool”项目。
有谁知道如何解决这个问题?或者另一种方式来访问配置的C++编译器设置? (除了手动解析vcxproj XML文件)
如果我打印出cfg.Tools中每个项目的ToString()值,我只会看到'shims',例如'Microsoft.VisualStudio.Project.VisualC.VCProjectEngine .VCCLCompilerToolShim”。
如果我在一个真正的VS2010宏(它工作)中做同样的事情,每个项目显示为'System .__ ComObject'。
在互联网上搜索表明,'shim'错误意味着代码正在访问错误版本的VCProjectEngine或VCProject程序集。我确实安装了VS2005和VS2010供其他项目使用,但我暂时将这些DLL的旧版本所在的每个地方重新命名,并仍然遇到同样的问题。也许它仍然从其他地方获得它,比如GAC?
我试图从IVCCollection.Item方法文档https://msdn.microsoft.com/en-US/library/microsoft.visualstudio.vcprojectengine.ivccollection.item(v=vs.140).aspx插入到Visual Commander命令中的样本,并得到了相同的结果。
Imports EnvDTE
Imports EnvDTE80
Imports Microsoft.VisualBasic
Imports System
Imports System.Diagnostics
Imports Microsoft.VisualStudio.VCProjectEngine
Imports System.Text
Public Class C
Implements VisualCommanderExt.ICommand
Sub Run(DTE As EnvDTE80.DTE2, package As Microsoft.VisualStudio.Shell.Package) Implements VisualCommanderExt.ICommand.Run
EnablePREfastExample(DTE)
End Sub
Sub EnablePREfastExample(ByVal dte As DTE2)
Dim prj As VCProject
Dim cfgs, tools As IVCCollection
Dim cfg As VCConfiguration
Dim tool As VCCLCompilerTool
Dim sb As New StringBuilder
prj = CType(dte.Solution.Projects.Item(1).Object, _
Microsoft.VisualStudio.VCProjectEngine.VCProject)
cfgs = CType(prj.Configurations, _
Microsoft.VisualStudio.VCProjectEngine.IVCCollection)
cfg = CType(cfgs.Item(1), _
Microsoft.VisualStudio.VCProjectEngine.VCConfiguration)
' This fails
tool = CType(cfg.Tools("VCCLCompilerTool"), _
Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
sb.Length = 0
sb.Append("Current project PREfast setting: " _
& tool.EnablePREfast & Environment.NewLine)
sb.Append("Flag: " & tool.AdditionalOptions)
MsgBox(sb.ToString)
End Sub
End Class
我将Visual Commander中的References ...对话框中的值设置为“Microsoft.VisualStudio.VCProjectEngine”。 (我还尝试完全指定路径名称,如“C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ PublicAssemblies \ Microsoft.VisualStudio.VCProjectEngine.dll”,或完整的GAC名称,如“Microsoft.VisualStudio .VCProjectEngine,Version = 14.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a“并得到了同样的错误结果。)