Creating a New Project
2008-12-18 17:11
295 查看
CreatingaNewProject
Toprogrammaticallycreateaproject
StartVisualStudioandcreateanewVisualStudioadd-inproject.Addthecodebelowtotheadd-in'sConnectclass.
Runtheadd-inprojectandactivateitintheAdd-InManager.
Todothis,clickAdd-InManagerontheToolsmenuandthenchecktheboxnexttotheadd-intoactivateit.
Example
ThefollowingexampleusesGetProjectTemplateandAddFromTemplatetocreatetwonewconsoleprojects,oneVisualBasicandtheotherVisualC#,inasolution.VisualBasic
PublicSubOnConnection(ByValapplicationAsObject,ByVal_
connectModeAsext_ConnectMode,ByValaddInInstAsObject,_
ByRefcustomAsArray)ImplementsIDTExtensibility2.OnConnection
_applicationObject=CType(application,DTE2)
_addInInstance=CType(addInInst,AddIn)
createProjectsFromTemplates(_applicationObject)
EndSub
SubcreateProjectsFromTemplates(ByValdteAsDTE2)
Try
'Createasolutionwithtwoprojectsinit,basedonproject
'templates.
DimsolnAsSolution2=CType(DTE.Solution,_
Solution2)
DimcsTemplatePathAsString
DimvbTemplatePathAsString
DimcsPrjPathAsString=_
"C:/UserFiles/kempb/addins/MyCSProject"
DimvbPrjPathAsString=_
"C:/UserFiles/kempb/addins/MyVBProject"
'GettheprojecttemplatepathforaC#consoleproject.
'ConsoleApplicationisthetemplatenamethatappearsinthe
'rightpane,"CSharp"istheLanguage(vstemplate)asseenin
'theregistry.
csTemplatePath=soln.GetProjectTemplate_
("ConsoleApplication.zip","CSharp")
MsgBox("C#templatepath:"&csTemplatePath)
'GettheprojecttemplatepathforaVisualBasic
'consoleproject.
'"vbproj:istheDefaultProjectExtensionasseeninthe
'registry.
vbTemplatePath=soln.GetProjectTemplate_
("ConsoleApplication.zip","vbproj")
MsgBox("VisualBasictemplatepath:"&vbTemplatePath)
'CreateanewC#consoleprojectusingthetemplateobtained
'above.
soln.AddFromTemplate(csTemplatePath,csPrjPath,_
"NewCSharpConsoleProject",False)
'CreateanewVisualBasicconsoleprojectusingthetemplate
'obtainedabove.
soln.AddFromTemplate(vbTemplatePath,vbPrjPath,_
"NewVisualBasicConsoleProject",False)
CatchexAsSystem.Exception
MsgBox("ERROR:"&ex.ToString)
EndTry
EndSub
C#
publicvoidOnConnection(objectapplication,ext_ConnectMode
connectMode,objectaddInInst,refArraycustom)
{
_applicationObject=(DTE2)application;
_addInInstance=(AddIn)addInInst;
createProjectsFromTemplates(_applicationObject);
}
publicvoidcreateProjectsFromTemplates(DTE2dte)
{
try
{
//Createasolutionwithtwoprojectsinit,basedonproject
//templates.
Solution2soln=(Solution2)dte.Solution;
stringcsTemplatePath;
stringvbTemplatePath;
stringcsPrjPath="C://UserFiles//kempb//addins//MyCSProject";
stringvbPrjPath="C://UserFiles//kempb//addins//MyVBProject";
//GettheprojecttemplatepathforaC#consoleproject.
//ConsoleApplicationisthetemplatenamethatappearsin
//therightpane."CSharp"istheLanguage(vstemplate)asseen
//intheregistry.
csTemplatePath=soln.GetProjectTemplate("ConsoleApplication.zip",
"CSharp");
System.Windows.Forms.MessageBox.Show("C#templatepath:"+
csTemplatePath);
//GettheprojecttemplatepathforaVisualBasicconsole
//project.
//"vbproj:istheDefaultProjectExtensionasseeninthe
//registry.
vbTemplatePath=soln.GetProjectTemplate("ConsoleApplication.zip",
"vbproj");
System.Windows.Forms.MessageBox.Show("VisualBasictemplatepath:"+
vbTemplatePath);
//CreateanewC#consoleprojectusingthetemplateobtained
//above.
soln.AddFromTemplate(csTemplatePath,csPrjPath,"NewCSharp
ConsoleProject",false);
//CreateanewVisualBasicconsoleprojectusingthetemplate
//obtainedabove.
soln.AddFromTemplate(vbTemplatePath,vbPrjPath,"NewVBConsole
Project",false);
}
catch(System.Exceptionex)
{
System.Windows.Forms.MessageBox.Show("ERROR:"+ex.Message);
}
}
相关文章推荐
- Creating a new Storm project
- Creating a New Xcode Project for ArcGIS
- On Creating New Project in VS2013: Failed to Initialize the Powershell Host
- Eclipse “Invalid Project Description” when creating new project from existing source
- 2010年8月29日周日_Creating a New Xcode Project_3
- Eclipse “Invalid Project Description” when creating new project from existing source
- Tips: compilation and creating new projects on Android 4.0
- Training ------ Building Your First App ------ Creating An Android Project
- Creating a Web Site with Flash: Visual QuickProject Guide
- pycharm new project变成灰色
- Creating New Material Nodes in UE4
- Creating a new application
- Microsoft buildup new website for open-source project
- 解决MyEclipse无法import/new project的问题
- Eclipse New菜单中没有Android Project选项
- [Django] Start a new django project
- 翻译qmake文档(三) Creating Project Files
- eclipse:File->New没有Android Application Project的解决办法
- Error Creating Project: Invalid project description
- Eclipse:File-->New File没有Android Application Project的解决办法