Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Adding a project programatically
 

Adding a project programatically

Hello everyone,

Search didn't find any usefull posts for this issue.

I added a context menu on solution level, from which you can add a web project.

I defined an Action to add the project to the solution, but actually I have no idea where to start to add the project to the solution programatically, I'm used to adding them in the xml-files.

I've looked into the EvnDTE with Reflector, but can't find a proper solution to do it.

Could anyone help me out?

Thanks in advance.

Nocto

Nocto  Wednesday, December 19, 2007 1:52 PM
Hi,

First of all, you have to create a .vstemplate, for more information about vstemplates check here:
http://msdn2.microsoft.com/es-es/library/31cdwx28(VS.80).aspx

Once you have your .vstemplate file done, you can create a recipe which use the UnfoldTemplateAction. This action can be found at Microsoft.Practices.RecipeFramework.Library.

hth.
jose.
Jose Escrich  Wednesday, December 19, 2007 2:36 PM
Hi,

First of all, you have to create a .vstemplate, for more information about vstemplates check here:
http://msdn2.microsoft.com/es-es/library/31cdwx28(VS.80).aspx

Once you have your .vstemplate file done, you can create a recipe which use the UnfoldTemplateAction. This action can be found at Microsoft.Practices.RecipeFramework.Library.

hth.
jose.
Jose Escrich  Wednesday, December 19, 2007 2:36 PM

Thans Jose,

As you said, I'm using the UnfoldTemplateAction (I already had the .vstemplate prepared).

I'm adding the project as follows:

using (UnfoldTemplateAction unfoldAction = new UnfoldTemplateAction())

{

base.Container.Add(unfoldAction);

unfoldAction.Template = "../Templates/Solutions/Projects/Web/WebUIProject.vstemplate";

unfoldAction.ItemName = "?";

}

Reflector tells me that the ItemName is a required input parameter, only I can't figure out what I should put in it, so for now I'm using the projectName.

Let's see how that goes.

Thanks for the reply!

Nocto

Nocto  Wednesday, December 19, 2007 3:10 PM
Hi,

ItemName is just the name that you want for the new Project or ProjectItem, note that the unfoldtemplateaction will not show any UI, it will just add the project.

btw, I did an extended UnfoldTemplateAction which resolve an replacement paremeter issue, you can get it here:
http://weblogs.asp.net/jescrich/archive/2007/10/05/dealing-with-the-unfoldtemplateaction-and-parameter-replacement.aspx

Jose Escrich  Wednesday, December 19, 2007 3:16 PM

Hello,

I implemented the extended UnfoldTemplateAction you wrote, but I continue to have problems.

In my case, the template I want to use is known, so I link to a physical location.

However, when I trie to run the guidance package, I get the following error:

Output window created.

(*) Error: 0 : Microsoft.Practices.RecipeFramework.ActionExecutionException: An exception occurred during the binding of reference or execution of recipe AddWebProject. Error was: Action AddWebProject failed to execute:

Invalid URI: The URI is empty..

You can remove the reference to this recipe through the Guidance Package Manager. ---> System.UriFormatException: Invalid URI: The URI is empty.

at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)

at System.Uri..ctor(String uriString)

at Microsoft.VisualStudio.TemplateWizard.Wizard.Execute(Object application, Int32 hwndOwner, Object[]& ContextParams, Object[]& CustomParams, wizardResult& retval)

at EnvDTE.SolutionClass.AddFromTemplate(String FileName, String Destination, String ProjectName, Boolean Exclusive)

at Microsoft.Practices.RecipeFramework.Library.Templates.Actions.UnfoldTemplateAction.AddProjectTemplate(Project project)

at Microsoft.Practices.RecipeFramework.Library.Templates.Actions.UnfoldTemplateAction.Execute()

at SDWORX.SmartTools.SmartToolsGAT.Actions.AddWebProjectAction.Execute() in C:\TFSPROJECTS\bougrial\SmartTools\Common\SDWORX.SmartTools.SmartToolsGAT\SDWORX.SmartTools.SmartToolsGAT\Actions\AddWebProject.cs:line 77

at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName, Dictionary`2 inputValues)

at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionExecutionService.Execute(String actionName)

at Microsoft.Practices.RecipeFramework.Recipe.Microsoft.Practices.RecipeFramework.Services.IActionCoordinationService.Run(Dictionary`2 declaredActions, XmlElement coordinationData)

at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution)

--- End of inner exception stack trace ---

at Microsoft.Practices.RecipeFramework.Recipe.UndoExecutedActionsAndRethrow(Exception ex)

at Microsoft.Practices.RecipeFramework.Recipe.ExecuteActions(IDictionaryService readOnlyArguments, IDictionaryService arguments, ITypeResolutionService resolution)

at Microsoft.Practices.RecipeFramework.Recipe.Execute(Boolean allowSuspend)

at Microsoft.Practices.RecipeFramework.GuidancePackage.Execute(String recipe, IAssetReference reference, IDictionary arguments)

at Microsoft.Practices.RecipeFramework.GuidancePackage.Execute(IAssetReference reference)

at Microsoft.Practices.RecipeFramework.RecipeReference.OnExecute()

at Microsoft.Practices.RecipeFramework.VisualStudio.VsBoundReference.OnExecute()

at Microsoft.Practices.RecipeFramework.AssetReference.Execute()

at Microsoft.Practices.RecipeFramework.VisualStudio.RecipeMenuCommand.OnExec()

at Microsoft.Practices.RecipeFramework.VisualStudio.AssetMenuCommand.Invoke()

This is the recipe I use to trigger the action:

<Recipe Name="AddWebProject" Recurrent="false">

<Types>

<xi:include href="TypeAlias.xml" xmlns:xi="http://www.w3.org/2001/XInclude" xpointer="xmlns(gax=http://schemas.microsoft.com/pag/gax-core) xpointer(gax:Types/gax:TypeAlias)" />

<TypeAlias Name="SolutionConverter" Type="Microsoft.Practices.RecipeFramework.Library.Converters.SolutionConverter, Microsoft.Practices.RecipeFramework.Library" />

</Types>

<Caption>Add a Web-User Interface project.</Caption>

<HostData>

<Icon ID="1046"/>

<CommandBar Name="Solution"/>

</HostData>

<Actions>

<Action Name="AddWebProject" Type="Prefix.GAT.Actions.AddWebProjectAction, Prefix.GAT">

</Action>

</Actions>

</Recipe>

This is the vstemplate I use for the web-application:

<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">

<TemplateData>

<Name>Prefix.CustomerName.CustomerProjectName.WebUI</Name>

<Description>Web User Interf</Description>

<ProjectType>Web</ProjectType>

<ProjectSubType>CSharp</ProjectSubType>

<SortOrder>1000</SortOrder>

<CreateNewFolder>true</CreateNewFolder>

<DefaultName>Prefix.CustomerName.CustomerProjectName.WebUI</DefaultName>

<ProvideDefaultName>true</ProvideDefaultName>

<LocationField>Enabled</LocationField>

<EnableLocationBrowseButton>true</EnableLocationBrowseButton>

<Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4547" />

</TemplateData>

<TemplateContent>

<Project TargetFileName="WebUIProject.webproj" File="WebUIProject.webproj" ReplaceParameters="true">

<Folder Name="App_Data" TargetFolderName="App_Data" />

<Folder Name="UserControls" TargetFolderName="UserControls" />

<Folder Name="Pages" TargetFolderName="Pages" />

<Folder Name="images" TargetFolderName="images" />

<Folder Name="css" TargetFolderName="css" />

<Folder Name="scripts" TargetFolderName="scripts" />

<ProjectItem ReplaceParameters="true" TargetFileName="Global.asax">Global.asax</ProjectItem>

<ProjectItem ReplaceParameters="true" TargetFileName="Web.config">Web.config</ProjectItem>

</Project>

</TemplateContent>

<WizardExtension>

<Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>

<FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName>

</WizardExtension>

<WizardData>

<Template xmlns="http://schemas.microsoft.com/pag/gax-template" SchemaVersion="1.0">

</Template>

</WizardData>

</VSTemplate>

Could anyone tell me what I'm overseeing?

Thanks in advance

Nocto

Nocto  Friday, December 21, 2007 7:52 AM

Hi Nocto,

As far as I understand from the error pasted above, the prolem lies in your Action class AddWebProjectAction. If you can show the action class, may be I will be in a position to solve your problem.

Regards,

-Noor

Noor Mohammed  Thursday, January 10, 2008 4:45 AM

You can use google to search for other answers

Custom Search

More Threads

• Processing T4 in different languages
• Starting VS2008 SP1 Beta1 In Experimental Hive Fails with Recipe Framework Error
• What causes the project to be added under Guidance Packages when creating a new project?
• GAT/GAX February 2007 CTP now available
• Null reference Exception after upgrade to GAX 1.2
• GAT July 2007 Cannot Find ENVDTE
• December 2005 CTP Required
• Calling Parent CDocument
• Executing same T4 action several times with different parameter values
• The following arguments are required and don't have values