【问题标题】:Cannot find VCCLCompilerTool in VS2015 macro (using Visual Commander)在 VS2015 宏中找不到 VCCLCompilerTool(使用 Visual Commander)
【发布时间】:2015-12-02 23:54:14
【问题描述】:

我正在使用 Visual Commander(来自 https://vlasovstudio.com/visual-commander/)来移植一些宏,用于将 C++ 项目从 VS2010 操作到 VS2015。一切似乎都正常(我可以访问解决方案、创建 VCProjects、循环通过配置等),但我遇到了一个问题 - 在 VS2010 中有效的调用:

cfg.Tools("VCCLCompilerTool")

...在 VS2015 中失败,出现“System.MissingMemberException:未找到类型 'VCollectionShim' 的默认成员。”错误,提示该集合没有“VCCLCompilerTool”项。

有谁知道如何解决这个问题?或者另一种访问配置的 C++ 编译器设置的方法? (除了手动解析 vcxproj XML 文件。)

如果我打印出 cfg.Tools 中每个项目的 ToString() 值,我只会看到“垫片”,例如“Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCCLCompilerToolShim”。

如果我在真正的 VS2010 宏中执行相同操作(有效),每个项目都会显示为“System.__ComObject”。

在 Internet 上搜索表明“shim”错误意味着代码正在访问错误版本的 VCProjectEngine 或 VCProject 程序集。我确实安装了 VS2005 和 VS2010 以用于其他项目,但我暂时重命名了这些 DLL 的旧版本所在的每个地方,但仍然遇到同样的问题。也许它仍然从其他地方获得它,比如 GAC?

我尝试将来自https://msdn.microsoft.com/en-US/library/microsoft.visualstudio.vcprojectengine.ivccollection.item(v=vs.140).aspx 的 IVCollection.Item 方法文档中的示例插入到 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”,得到同样的坏结果。)

【问题讨论】:

    标签: c++ visual-studio-2015 visual-studio-macros


    【解决方案1】:

    感谢 Visual Commander 的作者 Sergey Vlasov,我找到了答案。他指出,示例代码的 C# 版本在 VS2015 中运行。有问题的行中的 C# 和 VB 代码略有不同。 C#代码是:

    tool = 
      (Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
      tools.Item("VCCLCompilerTool");
    

    而VB代码是:

    tool = CType(cfg.Tools("VCCLCompilerTool"), _
      Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
    

    这个 VB 在 VS2010 中运行良好,但在 VS2015 中看起来,Tools 集合默认不能再按名称索引。所以我只需要添加“.Item”,它将VB代码更改为:

    tool = CType(cfg.Tools.Item("VCCLCompilerTool"), _
      Microsoft.VisualStudio.VCProjectEngine.VCCLCompilerTool)
    

    现在这个宏一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多