在我的WPF应用程序中,我尝试创建VS2105解决方案并使用EnvDte向其添加现有的vc项目。创建和保存解决方案没有问题。但是,当我尝试添加项目时,它会抛出。
private void CreateSolution(string path, string projectName)
{
var solutionName = projectName;
// VS2015Instance is a EnvDte80.DTE2
VS2015Instance.Solution.Create(path, solutionName);
var projectFullPath = Path.Combine(path, @"Scripts\");
var fullPath = Path.Combine(projectFullPath, ProjectName + ".vcxproj");
// This call throws exception
((EnvDTE80.Solution2)VS2015Instance.Solution).AddFromFile(fullPath);
var solutionFullFileName = Path.Combine(path, solutionName + ".sln");
VS2015Instance.Solution.SaveAs(solutionFullFileName);
}
例外情况如下:
System.Exception: An exception was thrown while initializing part "Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.VCLegacyEventsTranslator". at EnvDTE80.Solution2.AddFromFile(String FileName, Boolean Exclusive)
我不明白我做错了什么。这VCLegacyEventsTranslator
的东西是什么?做我想做的最好的方法是什么?有没有更好的选择?