Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以编程方式将现有项目添加到新的VS2012解决方案失败_C#_Visual Studio 2012_Envdte - Fatal编程技术网

C# 以编程方式将现有项目添加到新的VS2012解决方案失败

C# 以编程方式将现有项目添加到新的VS2012解决方案失败,c#,visual-studio-2012,envdte,C#,Visual Studio 2012,Envdte,向导中有以下代码,用于将现有项目添加到新解决方案: //generating files if (dte.Solution.Projects.Count < 1) // Solution is empty or doesn't exist { dte.Solution.Create(oneFolderHigher(Params.OutputDir, solutionName), solutionFileName(solutionNam

向导中有以下代码,用于将现有项目添加到新解决方案:

//generating files
if (dte.Solution.Projects.Count < 1) // Solution is empty or doesn't exist
{
    dte.Solution.Create(oneFolderHigher(Params.OutputDir, solutionName),
                        solutionFileName(solutionName));
}

// adding created project to solution
dte.Solution.AddFromFile(Path.Combine(Params.ProjectRootFolder, 
                                      Params.ProjectName + ".csproj"));
//生成文件
if(dte.Solution.Projects.Count<1)//解决方案为空或不存在
{
创建(oneFolderHigher(Params.OutputDir,solutionName),
solutionFileName(solutionName));
}
//将创建的项目添加到解决方案
dte.Solution.AddFromFile(Path.Combine(Params.ProjectRootFolder,
Params.ProjectName+“.csproj”);
它在MS Visual Studio 2010下运行良好,但在2012年下失败(我尝试了第二个参数):

System.Runtime.InteropServices.COMException(0x80004004):操作中止(来自HRESULT的异常:0x80004004(E_中止)) 位于EnvDTE.SolutionClass.AddFromFile(字符串文件名,布尔独占) 在Wizard.Generator.NewProjectGenerator.Generate(操作'1 logMessage) 在Wizard.Forms.WizardForm.Finish()中

在这个错误之后,我手动将新项目添加到解决方案中,一切正常。但我们不能只是说,“对不起,我们不能为您添加新生成的项目,所以请您自己添加。”

MSDN建议:

如果要在执行过程中抑制向导的UI,可以使用LaunchWizard方法而不是AddFromFile来执行向导。LaunchWizard有一个允许您禁用UI的参数

但此方法需要一些向导文件,因此它不是解决方案

有人能帮忙吗?
向导正在从“新建->项目”菜单运行。

这里是解决问题的方法(由我的老板提出):

但代码有点难看:

using (StreamReader sr = new StreamReader(newFile))
using (StreamWriter sw = new StreamWriter(projectFile, false, Encoding.UTF8))
{
     while (sr.Peek() >= 0)
     {
         string s = sr.ReadLine();
         if (s.Contains("<Project ToolsVersion=\"4.0\""))
         {
              s = s + Environment.NewLine + importProject;
         }
... and so on
使用(StreamReader sr=newstreamreader(newFile))
使用(StreamWriter sw=newstreamwriter(projectFile,false,Encoding.UTF8))
{
而(sr.Peek()>=0)
{
字符串s=sr.ReadLine();

如果(s)包含(“此处为该问题的解决方法(由我的老板提出):

但代码有点难看:

using (StreamReader sr = new StreamReader(newFile))
using (StreamWriter sw = new StreamWriter(projectFile, false, Encoding.UTF8))
{
     while (sr.Peek() >= 0)
     {
         string s = sr.ReadLine();
         if (s.Contains("<Project ToolsVersion=\"4.0\""))
         {
              s = s + Environment.NewLine + importProject;
         }
... and so on
使用(StreamReader sr=newstreamreader(newFile))
使用(StreamWriter sw=newstreamwriter(projectFile,false,Encoding.UTF8))
{
而(sr.Peek()>=0)
{
字符串s=sr.ReadLine();

如果(s.Contains)(“您正试图使用什么COM文件?此外,您是否向Microsoft报告了此问题?完全可能只是一个bug。我正在使用下一个DLL:EnvDTE[8.0.0.0]、EnvDTE80[8.0.0.0]、Extensibility[7.0.3300.0]、VSLangProj[7.0.3300.0]、Microsoft Visual Studio命令栏8.0、Microsoft.VisualStudio.OLE.Interop[7.1.40304.0],Microsoft.VisualStudio.Shell.Interop[7.1.40304.0],Microsoft.VisualStudio.Shell.Interop.8.0谢谢,我将尝试与Microsoft支持部门联系。我已创建了错误报告:如果您面临相同的问题,请投票支持。您正试图使用的COM文件到底是什么?此外,您是否已向Microsoft报告过此问题?完全可能只是一个错误。我正在使用下一个DLL:EnvDTE[8.0.0.0],EnvDTE80[8.0.0.0],可扩展性[7.0.3300.0],VSLangProj[7.0.3300.0],Microsoft Visual Studio命令栏8.0,Microsoft.VisualStudio.OLE.Interop[7.1.40304.0],Microsoft.VisualStudio.Shell.Interop[7.1.40304.0],Microsoft.VisualStudio.Shell.Interop.8.0谢谢,我将尝试与Microsoft支持部门联系。我已创建错误报告:如果遇到相同的问题,请投票支持。运行“devenv.exe/upgrade PROJECT\u FILE”运行“devenv.exe/upgrade PROJECT\u FILE”