在VS2015宏中找不到VCCLCompilerTool(使用Visual Commander)
Cannot find VCCLCompilerTool in VS2015 macro (using Visual Commander)
我正在使用Visual Commander(来自https://vlasovstudio.com/visual-commander/)将一些用于操作C++项目的宏从VS2010移植到VS2015。事情似乎还可以(我可以访问解决方案,创建VCProjects,循环通过配置等),但我有一个问题-在VS2010中工作的调用:
cfg.Tools("VCCLCompilerTool")
在VS2015中失败,返回"System.MissingMemberException:找不到类型"VCCollectionShim"的默认成员。"错误,表明集合没有"VCCLCompilerTool"项。
有人知道怎么解决这个问题吗?或者以另一种方式访问配置的C++编译器设置?(除了手动解析vcxproj XML文件。)
如果我打印出cfg中每个项的ToString()值。工具,我只看到"垫片",如"Microsoft.VisualStudio.Project.VICProjectEngine.VCCLCompilerToolShim".
如果我在一个真正的VS2010宏中也这样做(有效),则每个项都显示为"System"__ComObject"。
在互联网上搜索表明,"shim"错误意味着代码访问了错误版本的VCProjectEngine或VCProject程序集。我确实安装了VS2005和VS2010以供其他项目使用,但我暂时重命名了这些DLL旧版本所在的每个地方,但仍然遇到同样的问题。也许它还是从其他地方得到的,比如广汽?
我尝试插入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.Visual Studio.VCProjectEngine.dll",或GAC全名,如"Microsoft.VisualStudio.VCProjectEngine,Version=14.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a",并得到相同的错误结果。)
感谢《视觉指挥官》的作者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)
现在这个宏一切都很好。
- 如何使用Visual Studio 2017在C++中为参数化对象数组使用唯一指针
- 使用visual studio 2019正确设置tinycc,找不到库libtcc1-32.a
- 在Windows 10上使用Visual Studio 2019构建的Tesseract API c ++程序在Wind
- 使用 Visual Studio 2019 构建 Hello World wxwidgets 应用程序时出错
- 如何在调试中使用Visual Studio正确编译WebRTC?
- 带有自动参数的函数使用 GCC 编译,但不使用 Visual C++ 编译
- C++ 使用 Visual Studio 2020 不能使用 .length()
- 使用Visual Studio在虚幻引擎中创建一个新的类c ++给了我太多的错误
- 使用 Visual Studio 2019 编译 Unicode
- C++20 使用 Visual Studio 编译模块:不编译或导入 ixx 文件
- 如何使用Visual Studio 2008将字符串映射到函数?
- 使用Visual Studio 2012编译时,此代码会给我错误,但是使用代码块就可以了
- 使用 Visual Studio C++ 在控制台中控制字体和字符集
- 使用 Visual Studio 代码读取 C++ 中的输入流时出错
- 需要有关使用 Visual Studio 17 将 QT 桌面应用程序打包为 AppX 格式的指导
- 在Windows 10上使用Visual Studio 2019的Boost 1.71.0库出现错误
- 试图弄清楚我需要做哪些更改才能使代码正常工作.使用Visual Studio
- 使用Visual Studio进行跨平台C++开发
- 使用Visual Studio code Ubuntu调试c++代码
- 如何在Ubuntu中使用Visual Studio代码编译C++代码