VS 2010的自动化操作。
从启动visual studio,到创建solution,到创建一个Console Applciation。
代码中有几处bug,比如已经存在的目录需要删除,但是没有删,没办法,手工删除吧。
本来还想添加工程引用,添加引用,利用EditPoint输入文本。考虑到时间不早了,所以不写了,以后会继续写代码。
Module Module1
Sub Main()
' -----------------------------------------------------------------
' (1) Initializes the vs object and launching Visual Studio.
' -----------------------------------------------------------------
Dim vsDTE As EnvDTE.DTE
Dim vsDteType As Type = Type.GetTypeFromProgID("VisualStudio.DTE.10.0")
' Now vs is initialized.
vsDTE = Activator.CreateInstance(vsDteType)
' Set the main window is visible to see the Visual Studio.
vsDTE.MainWindow.Visible = True
' -----------------------------------------------------------------
' (2) Create solution with console template.
' -----------------------------------------------------------------
Dim solnName As String = "MyTestSolution"
Dim solnSavePath As String = "C:/VSProjs/"
Dim consoleAppTemplate As String =
"C:/Program Files/Microsoft Visual Studio 10.0/Common7/IDE/ProjectTemplatesCache/VisualBasic/Windows/1033/ConsoleApplication.zip/consoleapplication.vstemplate"
Dim soln As EnvDTE.Solution = vsDTE.Solution
' Dim soln2 As EnvDTE80.Solution2 = vsDTE.Solution
Dim proj As EnvDTE.Project
Dim proj2 As EnvDTE.Project
'
' Delete the previous folder that created.
'
If System.IO.Directory.Exists("C:/VSProjs") Then
System.IO.Directory.Delete(solnSavePath)
End If
'
' Creates a solution with naming "MyTestSolution" and saved it under c:/VSProjs./
'
soln.Create(solnSavePath, solnName) ' Here, there is a problem, when creating a solution the save as dialog always prompt.
soln.Saved = False
proj = soln.AddFromTemplate(consoleAppTemplate, solnSavePath, "MyTestProj", True)
proj.Save()
proj2 = soln.AddFromTemplate("C:/Program Files/Microsoft Visual Studio 10.0/Common7/IDE/ProjectTemplatesCache/VisualBasic/Windows/1033/ClassLibrary.zip/ClassLibrary.vstemplate", solnSavePath, "MyTestClsLibrary", True)
' Stop to see what will happen.
Stop
End Sub
End Module