Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Get a project reference to a website project
 

Get a project reference to a website project

My guidance package creates a web site project using the following template:

<VSTemplate Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project">
<TemplateData>
<Name>WebSite</Name>
<Description>&lt;No description available&gt;</Description>
<Icon Package="{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}" ID="4547" />
<ProjectType>Web</ProjectType>
<ProjectSubType>CSharp</ProjectSubType>
<SortOrder>1000</SortOrder>
<CreateNewFolder>true</CreateNewFolder>
<DefaultName>WebSite</DefaultName>
<ProvideDefaultName>true</ProvideDefaultName>
<LocationField>Enabled</LocationField>
<EnableLocationBrowseButton>true</EnableLocationBrowseButton>
</TemplateData>
<TemplateContent>
<Project TargetFileName="$HostProjectName$.webproj" File="WebSite.webproj" ReplaceParameters="true">
<ProjectItem ReplaceParameters="true">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>
</VSTemplate>




Some other recipe in my guidance package needs a reference to this web site project.
So, I tried to get the web site project using the Microsoft.Practices.RecipeFramework.Library.Actions.GetProjectAction action. But it always returns null for my web site project.
The action to get the web site project looks like this, where the HostProjectName argument contains the value "WebSite":

<Action Name="GetHostProject" Type="Microsoft.Practices.RecipeFramework.Library.Actions.GetProjectAction, Microsoft.Practices.RecipeFramework.Library">
<Input Name="ProjectName" RecipeArgument="HostProjectName" />
<Output Name="Project" />
</Action>



Does anyone know how to get a reference to a web site project? Do I have to use another action then GetProjectAction?

Greets,
Nils Gruson
ngruson  Tuesday, March 11, 2008 11:09 AM

Hi,
please check this thread, it should be useful
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2488647&SiteID=1
if not, please let me know.

jose.
Jose Escrich  Tuesday, March 11, 2008 5:44 PM

Hi Nils,

As per my understanding, you have unfolded awebsite project using your guidance package and you want that website project reference when you call some other recipe.

There are different approaches in which you can get the project reference.

1) If you are calling a recipe, which means that you will call that recipe on right click of some project in the solution or on the solution itself. If you are calling a recipe on right click of webproject then you can get the webproject argument by doing below:

a) CurrentProjectProvider Value Provider

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

<Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.ProjectConverter, Microsoft.Practices.RecipeFramework.Library" />

<ValueProvider Type="Microsoft.Practices.RecipeFramework.Extensions.ValueProviders.VisualStudio.CurrentProjectProvider, Microsoft.Practices.RecipeFramework.Extensions" />

</Argument>

b) FirstSelectedProject Value Provider

<Argument Name=" WebProject " 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>

2) If you are not calling a recipe on right click of webproject then you can get the webproject argument by doing below:

a) You need to specify responsiblility to you website, using which you can identify your website project

b) Then you can get the website project basing on the responsibility.

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

<Converter

Type="Microsoft.Practices.SoftwareFactories.ServiceFactory.Converters.ProjectWithResponsibilityConverter, Microsoft.Practices.SoftwareFactories.ServiceFactory"

ResponsibilityArgument="IsWebProject"/>

<ValueProvider Type="Microsoft.Practices.SoftwareFactories.ServiceFactory.ValueProviders.ProjectsWithResponsibilityProvider, Microsoft.Practices.SoftwareFactories.ServiceFactory"

ResponsibilityArgument="IsWebProject" />

Salaam/Namaste,

Noor

Noor Mohammed  Tuesday, March 11, 2008 12:47 PM

Hi,
please check this thread, it should be useful
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2488647&SiteID=1
if not, please let me know.

jose.
Jose Escrich  Tuesday, March 11, 2008 5:44 PM
Thanks Jose for your input,

I made a custom action to loop through the projects in the generated solution and check if the current project is the website by checking the projects name:

[ServiceDependency(typeof(DTE))]
public sealed class GetWebSiteAction : Action
{
#region Input Properties

private string projectName;
[Input(Required = true)]
public string ProjectName
{
get { return projectName; }
set { projectName = value; }
}

#endregion

#region Output Properties

private Project project;
[Output]
public Project Project
{
get { return project; }
}

#endregion

#region Action members

/// <summary>
/// <see cref="IAction.Execute"/>
/// </summary>
public override void Execute()
{
DTE dte = GetService<DTE>(true);
foreach (Project proj in dte.Solution.Projects)
{
if ((proj != null) && (proj.Name.Contains(projectName)))
project = proj;
}
}

/// <summary>
/// <see cref="IAction.Undo"/>
/// </summary>
public override void Undo()
{
}

#endregion
}



@Noor: I have to get a reference to the website project in the recipe that creates the solution. I want to apply a certain responsiblity to the website project when the solution gets created. At this time, the website hasn't any responsibilities set.

Greets,
Nils Gruson
ngruson  Wednesday, March 12, 2008 3:56 PM

You can use google to search for other answers

Custom Search

More Threads

• How can I Organize templates in the "new project" dialog?
• Path of Bin Folder for a given project
• Project References Guids?
• Linking the Smart Client Software Factory with GuidanceAutomationExtensions
• How to Validate Custom Argument
• how to re-enable register/unregister/quick register guidance package
• Can't create my own action
• GAX/GAT for VS 2005-2008 default templates removed
• Multiple Project Creation Template
• Visual Studio doesnot show Designer because of a project referenced dll not loading correctly...