2009-04-20 11 views
0

テストプロジェクトをプログラムでソリューションに追加しようとしています。しかし、以下のコードを実行すると、 "vhaSolution.GetProjectTemplate(" TestProject.zip "、" Csharp ")という行でFile IO例外が発生します。このエラーは、「指定した言語が、インストールされたパッケージのいずれでもサポートされていません」という意味です。誰かがこれを引き起こしている可能性のある考えを持っていますか?Visual Studioの拡張性、プログラムによるプログラムによる作成

public enum TestProjectType 
    { 
     Unit, 
     Acceptance, 
     Integration 
    } 

public static void CreateTestProject(string fullyQualifiedSolutionFileName,string projectName,TestProjectType testProjectType) 
     { 
      #region Argument Validation 
      if (String.IsNullOrEmpty(fullyQualifiedSolutionFileName) || String.IsNullOrEmpty(fullyQualifiedSolutionFileName.Trim())) 
      { 
       throw new ArgumentNullException("fullyQualifiedSolutionFileName", "The solution file location is required."); 
      } 

      if (String.IsNullOrEmpty(projectName) || String.IsNullOrEmpty(projectName.Trim())) 
      { 
       throw new ArgumentNullException("projectName", "The project name is required."); 
      } 

      if (!File.Exists(fullyQualifiedSolutionFileName)) 
      { 
       throw new ArgumentException(String.Format("The file {0} specified does not exist.", fullyQualifiedSolutionFileName)); 
      } 

      if (testProjectType == null) testProjectType = TestProjectType.Unit; 
      #endregion 

      System.Type vsType = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0"); 
      Object vs = System.Activator.CreateInstance(vsType, true); 
      EnvDTE80.DTE2 dte8Obj = (EnvDTE80.DTE2)vs; 

      Solution2 vhaSolution = (Solution2)dte8Obj.Solution; 
      vhaSolution.Open(fullyQualifiedSolutionFileName); 

      //TODO: Externalize company name 
      string cmpnyName = "Vha"; 
      string testProjectName = String.Format("{0}.{1}.{2}{3}",cmpnyName,projectName,testProjectType.ToString(),"Test"); 
      string testTemplateLocation = vhaSolution.GetProjectTemplate("TestProject.zip", "CSharp"); 
      FileInfo rootSolutionFolder = new FileInfo(fullyQualifiedSolutionFileName); 

      //TODO: Externalize test directory name 
      string testDirName = String.Format("{0}\\{1}\\{2}\\{3}",rootSolutionFolder.DirectoryName,"test",testProjectType.ToString(),testProjectName); 

      if (!Directory.Exists(testDirName)) 
      { 
       //may throw an exception if the dir can't be created... 
       Directory.CreateDirectory(testDirName); 
      } 


      Project vhaTestProj = vhaSolution.AddFromTemplate(testTemplateLocation,testDirName,testProjectName + ".proj",false); 
      vhaTestProj.Save(String.Format("{0}\\{1}.proj",testDirName , testProjectName)); 



     } 

答えて

3

私はそれを理解しました。 VS 2008の正しいレジストリ位置を指すように、prog ID VisualStudio.DTE.9.0を使用する必要があります。

関連する問題