Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Replacing Project Name
 

Replacing Project Name

I have a solution developed in Visual Basic with one Class Library and one website.

I have the custom template created and it works fine. However, the website always comes across as 'Site' or whatever I put in the vstemplate for the project name.

I am looking to have the developer choose one and have it update it. I was looking into WizardExtensions but have been unable to get it to work.

Now I am looking into GAT. Can someone point me where I should look for this since I have not seen examples that create web sites as well and being that its in VB and not C#?

Thanks.

Kosmo

Kosmo007  Monday, January 08, 2007 10:00 PM
Hi Kosmo,


GAX has its own wizard extension class:

<WizardExtension>
<Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName>
</WizardExtension>


This extensions let's you use GAX recipe arguments inside .vstemplate and .xxproj files. These GAX recipe arguments can be easily collected by a GAX Wizard which can be declaratively specified.

So if you use GAX/GAT you shouldn't need to use your own wizard extension as you will get the same results wihtout writing any code.

Please use GAT to create a sample Guidance Package solution, this guidance package contains a GAX wizard that asks you for two values one of which is a website name, and then it uses it to create a web site.

Please give that a try and let us know if it helped!

-Victor.
vga  Thursday, January 11, 2007 4:00 PM

Here's a bit more information that might help someone to answer my question.

I have a zip file with a root.vstemplate and two projects: Project1 and Project2. Project1 is a website and Project2 is a class library project. I want to be able to rename the website from Site which is given in the template below to whatever the developer chooses.

I have a wizard extension class that pops up a form and allows the user to input a website name. I am not sure if I can rename the project via the IWizard.RunFinished method or if I need to do something with GAT. I messed around with the RunFinished method but am not sure where to begin to accomplish what I need. Adding an item to replacementsDictionary.Add("$Site$", SiteName) does not help in the RunStart method.

Any help would be appreciated as I'm not sure if its doable through the WizardExtension or if I need to do something with GAT.

My root.vstemplate file looks like the following:

<VSTemplate xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Version="2.0.0" Type="ProjectGroup">
     <TemplateData>
      <Name>My Solution</Name>
      <Description>Solution for Web Application Team</Description>
      <Icon>__TemplateIcon.ico</Icon>
      <ProjectType>Web</ProjectType>
      <ProjectSubType>VisualBasic</ProjectSubType>
      <SortOrder>1000</SortOrder>
     <CreateNewFolder>true</CreateNewFolder>
     <DefaultName>WebApp</DefaultName>
     <ProvideDefaultName>true</ProvideDefaultName>
     <LocationField>Enabled</LocationField>
     <EnableLocationBrowseButton>true</EnableLocationBrowseButton>
    </TemplateData>
    <TemplateContent>
     <ProjectCollection>
      <ProjectTemplateLink ProjectName="Site" ReplaceParameters="true">Proj1\MyTemplate.vstemplate</ProjectTemplateLink>
      <ProjectTemplateLink ProjectName="App_BL">Proj2\MyTemplate.vstemplate</ProjectTemplateLink>
     </ProjectCollection>
    </TemplateContent>
    <WizardExtension>
  <Assembly>MyWizard, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9f749b9db5c7fb1c</Assembly>
  <FullClassName>MyWizard.Class1</FullClassName>
 </WizardExtension>
 
   </VSTemplate>

Thanks,

Kosmo

Kosmo007  Tuesday, January 09, 2007 6:54 PM
Hi Kosmo,


GAX has its own wizard extension class:

<WizardExtension>
<Assembly>Microsoft.Practices.RecipeFramework.VisualStudio, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</Assembly>
<FullClassName>Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate</FullClassName>
</WizardExtension>


This extensions let's you use GAX recipe arguments inside .vstemplate and .xxproj files. These GAX recipe arguments can be easily collected by a GAX Wizard which can be declaratively specified.

So if you use GAX/GAT you shouldn't need to use your own wizard extension as you will get the same results wihtout writing any code.

Please use GAT to create a sample Guidance Package solution, this guidance package contains a GAX wizard that asks you for two values one of which is a website name, and then it uses it to create a web site.

Please give that a try and let us know if it helped!

-Victor.
vga  Thursday, January 11, 2007 4:00 PM

Victor,

That is the process that I am currently working on.

I have it creating a website automatically with the name provided by the GAX wizard. I also have it creating a vb library for my business logic.

I changed the CreateSolution recipe to only ask for a website name and that is working correctly.

I am now trying to figure out how to add a reference to a dll located on my network to be available as a reference in the web project as well.

Also, when everything is done, how do I distribute this to the other developers here? I know they'll need GAX but after that I don't know how to give it to them. Previously, I zipped up all the files and vstemplate and pushed it out to the User Project Template Location.

If you can assist in either of these, it would be greatly appreciated.

Thanks,

Kosmo

Kosmo007  Thursday, January 11, 2007 7:35 PM

I found the following post in the forum:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=916721&SiteID=1

Is this what I need to do to add a reference to an assembly located at \\xxx\assemblies\myassembly.dll ?

Can the reference be added like \\xxx\assemblies\my.dll or must I copy the dll locally and add it that way through a folder in the GAT project?

Thanks,

Kosmo

Kosmo007  Thursday, January 11, 2007 7:42 PM
To add a file reference (instead of a project reference) to a project you can use the GAX action:

Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction

this action takes the file reference and the project where to add it to. Give it a try.

Regarding your deployment question, if you generated your GP solution using GAT you should have three projects already one of which is a VS Setup project which on building will generate a corresponding MSI that you can use to install your GP on any machine.

HTH,
-Victor.
vga  Thursday, January 11, 2007 9:28 PM

Victor,

Thanks for the reference.

I have not gotten it to work yet. I originally put the recipe pointer in the ClassLibrary.vstemplate and got an error about ProjectArg. After moving it to the root vstemplate it creates the solution and projects fine but does not include the file reference. I have tried moving the file to c:\MyAssembly.dll and that did not work either.

Here's what I have. In the root vstemplate file I have the following recipe:

<Recipe Name="AddAssemblies">
<
Caption>Automatically adds references to existing assemblies.</Caption>
<
Arguments>
<Argument Name="ReferenceNameArg">
<
ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.ExpressionEvaluatorValueProvider,Microsoft.Practices.RecipeFramework.Library" Expression="\\servername\is\projects\Assembly\Framework2.0\MyAssembly.dll"/>
</
Argument>
<
Argument Name="ProjectArg" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<
ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject, Microsoft.Practices.RecipeFramework.Library" />
</
Argument>
</
Arguments>
<
Actions>
<
Action Name="AddReference" Type="Actions.AddReferenceAction, Package">
<
Input Name="ReferenceName" RecipeArgument="ReferenceNameArg"/>
<
Input Name="ReferringProject" RecipeArgument="ProjectArg"/>
</
Action>
</
Actions>
</
Recipe>

In the solution template I have:

<ProjectCollection>
<
ProjectTemplateLink ProjectName="APP_BL">Projects\ClassLibrary\ClassLibrary.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$WebSiteName$">Projects\WebSite\WebSite.vstemplate</ProjectTemplateLink>
</
ProjectCollection>
...
<WizardData>
<
Template xmlns="http://schemas.microsoft.com/pag/gax-template" SchemaVersion="1.0" Recipe="CreateSolution"></Template>
<
Template xmlns="http://schemas.microsoft.com/pag/gax-template" SchemaVersion="1.0" Recipe="AddAssemblies"></Template>
</
WizardData>

I have found a similar example on a website but it seems as if I'm missing something.

Thanks,

Kosmo

Kosmo007  Friday, January 12, 2007 2:07 PM
Hi Kosmo,

GAX doesn't support specifying more than one <Template> in the <WizardData> element, that is by-design.

What I would do, is to add the actions that add the assembly file reference to the "CreateSolution" recipe and avoid having a separate recipe ("AddAssemblies") just to do that. Or is there any reason why you may want this last one to be a recipe?

HTH,
-Victor.
vga  Friday, January 12, 2007 6:11 PM

I moved

<Argument Name="ReferenceNameArg">
<
ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.ExpressionEvaluatorValueProvider,Microsoft.Practices.RecipeFramework.Library" Expression="c:\MyAssembly.dll"/>
</
Argument>
<
Argument Name="ProjectArg" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<
ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject, Microsoft.Practices.RecipeFramework.Library" />
</
Argument>

Under the Create solution recipe and moved

<Actions>
<Action Name="AddReference" Type="Actions.AddReferenceAction, Package">
<
Input Name="ReferenceName" RecipeArgument="ReferenceNameArg"/>
<
Input Name="ReferringProject" RecipeArgument="ProjectArg"/>
</
Action>
</
Actions>

after the GatheringServiceData section. I then receive this error:

Microsoft.Practices.RecipeFramework.ValueProviderException: An exception occurred during the binding of reference or execution of recipe CreateSolution. Error was: An error happened while calling the value provider or evaluating the default value of argument ProjectArg..

Thanks,

Kosmo

Kosmo007  Friday, January 12, 2007 6:30 PM
Can you paste the text for the GAX output window: go View->Output and look for the Microsoft Recipe Framework and GAT output windows. There you should much more detailed information on what's going on.

-Victor.
vga  Friday, January 12, 2007 6:49 PM

Here is the output window text.

Output window created.

(*) Error: 0 : Microsoft.Practices.RecipeFramework.ValueProviderException: An exception occurred during the binding of reference or execution of recipe CreateSolution. Error was: An error happened while calling the value provider or evaluating the default value of argument ProjectArg..

You can remove the reference to this recipe through the Guidance Package Manager. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.

at Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject.OnBeginRecipe(Object currentValue, Object& newValue)

at Microsoft.Practices.RecipeFramework.Recipe.CallProviders(IDictionary providers, IDictionaryService readonlyArguments, IDictionaryService arguments, Boolean isBefore)

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

at Microsoft.Practices.RecipeFramework.Recipe.CallProviders(IDictionary providers, IDictionaryService readonlyArguments, IDictionaryService arguments, Boolean isBefore)

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.ExecuteFromTemplate(String recipe, IDictionary arguments)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.ExecuteRecipe(Boolean executeActions)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.RunStarted(Object automationObject, Dictionary`2 replacementsDictionary, WizardRunKind runKind, Object[] customParams)

-Kosmo

Kosmo007  Friday, January 12, 2007 6:57 PM

Here is the output window text.

Output window created.

(*) Error: 0 : Microsoft.Practices.RecipeFramework.ValueProviderException: An exception occurred during the binding of reference or execution of recipe CreateSolution. Error was: An error happened while calling the value provider or evaluating the default value of argument ProjectArg..

You can remove the reference to this recipe through the Guidance Package Manager. ---> System.IndexOutOfRangeException: Index was outside the bounds of the array.

at Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject.OnBeginRecipe(Object currentValue, Object& newValue)

at Microsoft.Practices.RecipeFramework.Recipe.CallProviders(IDictionary providers, IDictionaryService readonlyArguments, IDictionaryService arguments, Boolean isBefore)

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

at Microsoft.Practices.RecipeFramework.Recipe.CallProviders(IDictionary providers, IDictionaryService readonlyArguments, IDictionaryService arguments, Boolean isBefore)

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.ExecuteFromTemplate(String recipe, IDictionary arguments)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.ExecuteRecipe(Boolean executeActions)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.RunStarted(Object automationObject, Dictionary`2 replacementsDictionary, WizardRunKind runKind, Object[] customParams)

-Kosmo

Kosmo007  Friday, January 12, 2007 6:57 PM
Looks like that FirstSelectedProject built-in value provider is throwning. I guess this may be because of the state of your just unfolded solution and the current selected item in solution explorer.

The code for the built-in FirstSelectedProject built-in value provider is pretty simple and may not be working on your case:

its' OnBeginRecipe method looks like this:

DTE vs = (DTE)GetService(typeof(DTE));
newValue = ((object[])vs.ActiveSolutionProjects)[0] as Project;
return true;

can you try writing your own value provider for this? You can use the above code as a jumpstart. This way you would be able to debug into it and examine what the solution explorer looks like at unfolding time, and why ActiveSolutionProjects array may be empty. Based on these findings you could write a more foolproof value provider to handle this.

let me know if this heps,
-Victor.

vga  Friday, January 12, 2007 7:40 PM

Victor,

After creating my own value provider, I received the same error message and was unable to resolve the issue.

Since then, I have been playing around with putting it in its own recipe and adding to my WebSite.vstemplate.

I now am able to get beyond the previous error but a new one pops up. Below is the code and the error output.

Your help is greatly appreciated.

Kosmo

<WizardData>

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

SchemaVersion="1.0"

Recipe="AddMyAssembly">

</Template>

</WizardData>

The recipe looks like this:

<Recipe Name="AddMyAssembly">

<Caption>Collects information for the new solution.</Caption>

<Arguments>

<Argument Name="ReferenceNameArg">

<ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.ExpressionEvaluatorValueProvider,Microsoft.Practices.RecipeFramework.Library" Expression="c:\MyAssembly.dll"/>

</Argument>

<Argument Name="ProjectArg" Type="EnvDTE.Project, EnvDTE, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">

<ValueProvider Type="Microsoft.Practices.RecipeFramework.Library.ValueProviders.FirstSelectedProject, Microsoft.Practices.RecipeFramework.Library" />

</Argument>

</Arguments>

<Actions>

<Action Name="AddReference" Type="Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction, Microsoft.Practices.RecipeFramework.VisualStudio.Library">

<Input Name="ReferenceName" RecipeArgument="ReferenceNameArg"/>

<Input Name="ReferringProject" RecipeArgument="ProjectArg"/>

</Action>

</Actions>

</Recipe>

Output window created.

(*) Error: 0 : System.NullReferenceException: Object reference not set to an instance of an object.

at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.IsTemplateFile(String filePath, String& content)

at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.ProcessFile(String filePath, ProjectItem prItem)

at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.ProcessProjectItem(ProjectItem prItem)

at Microsoft.Practices.RecipeFramework.VisualStudio.Library.Templates.T4UnfoldAction.Execute()

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.TemplateGatheringService.ProcessT4Templates()

(*) Error: 0 : System.TypeLoadException: Could not load type 'Microsoft.Practices.RecipeFramework.Library.Solution.Actions.AddReferenceAction' from assembly 'Microsoft.Practices.RecipeFramework.VisualStudio.Library, Version=1.0.60429.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

at System.Reflection.Assembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)

at Microsoft.Practices.Common.Services.TypeResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)

at Microsoft.Practices.Common.Services.AliasResolutionService.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)

at Microsoft.Practices.Common.Services.TypeResolutionService.GetType(String typeName, Boolean throwOnError)

at Microsoft.Practices.RecipeFramework.Recipe.GetInstance[T](ITypeResolutionService resolution, String concreteType)

at Microsoft.Practices.RecipeFramework.Recipe.LoadActionsFromConfiguration(ITypeResolutionService resolution)

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.ExecuteFromTemplate(String recipe, IDictionary arguments)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.ExecuteRecipe(Boolean executeActions)

at Microsoft.Practices.RecipeFramework.VisualStudio.Templates.UnfoldTemplate.RunFinished()

Kosmo007  Monday, January 15, 2007 10:02 PM

Victor,

Since I have gotten off topic from the original subject in this thread I have started a new one relating to my reference adding question in this forum.

Hopefully this might spark more feedback as well.

I will continue to check both and update as I continue trying to figure this out.

Thanks,

Kosmo

Kosmo007  Wednesday, January 17, 2007 4:25 PM

You can use google to search for other answers

Custom Search

More Threads

• Guidance Automation Toolkit July 2007 Bug
• Generating custom BAL after using repository factory
• Problem on installing GAT
• GAX - Integrated with DSL Tool
• CommandBars
• UnfoldTemplateAction - with template parameter
• GAT Roadmap
• Error creating ServiceContract, also not displaying my current project's DataContracts / FaultContracts???
• ExecutionCondition ForEach Actions
• Minor bug in VszWizard.FindAddItem