VS 扩展开发 EnvDTE.Project类型强转VCProject类型
—记录遇到的坑
针对C++项目扩展开发
ThreadHelper.ThrowIfNotOnUIThread();
//ThreadHelper.ThrowIfNotOnUIThread();
// Output related
IVsOutputWindow output =(IVsOutputWindow)Package.GetGlobalService(typeof(SVsOutputWindow));
output.CreatePane(CommandSet, "cyFastBuild", 1, 1);
IVsOutputWindowPane pane;
output.GetPane(CommandSet, out pane);
// Get solution related
var dte2 = Package.GetGlobalService(typeof(DTE)) as DTE;
var solution = dte2.Solution;
// Get start project
Project startupProject = DTE.Solution.Item(((DTE.Solution.SolutionBuild as SolutionBuild2).StartupProjects as object[])[0]);
VCProject VcProject = startupProject.Object as VCProject;
获取到的VCProject为空
原因分析:
引用Microsoft.VisualStudio.VCProjectEngine版本不对
解决方案:
vs2015 应该是14.0.0.0
vs2019应该是16.0.0.0