Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Enable recipie if assembly reference exist
 

Enable recipie if assembly reference exist


Existe the posibility of eneble or not, one recipe if the project where act have one reference to assembly specific.

The idea is that this is already exist and use, or create the action or code to get the functionality.

The idea is that only the unbound recipe enable to user in determined condition.

The condition in this case is the existence of one reference or not.

Is posible obtain this?

Thanks
Leandro Tuttini  Wednesday, September 26, 2007 9:34 PM

Hi Leandro,

yes that's possible, you have to write your own Reference, in the default guidance package that is unfolded by GAT you will findtwo examples (SolutionFolderRecipeReference y AnyElementReference). There you have to write your own code to determine when the recipe should appear or not.


Once you have the reference you have to add a new action in the binding recipe (also you have several examples in the default package), so that new action should look like this:

<Action Name="MyRecipeReference" Type="Microsoft.Practices.RecipeFramework.Library.Actions.CreateUnboundReferenceAction, Microsoft.Practices.RecipeFramework.Library" AssetName="MyRecipe"

ReferenceType="MyReference, MyProjectNamespace" />

Let me know if you also need help to get the project references.

hth

jose.

Jose Escrich  Thursday, September 27, 2007 1:22 AM

Hi Leandro,

yes that's possible, you have to write your own Reference, in the default guidance package that is unfolded by GAT you will findtwo examples (SolutionFolderRecipeReference y AnyElementReference). There you have to write your own code to determine when the recipe should appear or not.


Once you have the reference you have to add a new action in the binding recipe (also you have several examples in the default package), so that new action should look like this:

<Action Name="MyRecipeReference" Type="Microsoft.Practices.RecipeFramework.Library.Actions.CreateUnboundReferenceAction, Microsoft.Practices.RecipeFramework.Library" AssetName="MyRecipe"

ReferenceType="MyReference, MyProjectNamespace" />

Let me know if you also need help to get the project references.

hth

jose.

Jose Escrich  Thursday, September 27, 2007 1:22 AM

Thanks Jose, you answer has helped me very much.

Your sugestion is the solucion.

There the solution:

/////////////////////////////////////////////////////
Class ProjectAssemblyReference
////////////////////////////////////////////////////
using System;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Practices.RecipeFramework;
using EnvDTE;
using VSLangProj;
using Microsoft.Practices.Common;

using System.Security.Permissions;

namespace Microsoft.Services.BF.GuidancePackage.References
{
[Serializable]
public class ProjectAssemblyReference : UnboundRecipeReference, IAttributesConfigurable
{
private string assemblyNameName;
private const string AssemblyNameAttribute = "AssemblyReferenceName";

public ProjectAssemblyReference(string template)
: base(template)
{
}

public override bool IsEnabledFor(object target)
{
VSProject vsProject = GetProject(target);

if (vsProject != null)
{
//Iterate in each one of reference in the project, to determine the reference expected
foreach (Reference reference in vsProject.References)
{
if (reference.Name == assemblyNameName)
return true;
}
}

return false;

}

public override string AppliesTo
{
get { return "All project with reference to FeeManagement assembly"; }
}

#region ISerializable Members

/// <summary>
/// Required constructor for deserialization.
/// </summary>
protected ProjectAssemblyReference(SerializationInfo info, StreamingContext context)
: base(info, context)
{
assemblyNameName = info.GetString(AssemblyNameAttribute);
}

/// <summary>
/// Provides a serialization member that derived classes can override to add
/// data to be stored for serialization.
/// </summary>
[SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
protected override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
info.AddValue(AssemblyNameAttribute, assemblyNameName);
}
#endregion ISerializable Members

#region IAttributesConfigurable Members

/// <summary>
/// Configures the component using the dictionary of attributes specified
/// in the configuration file.
/// </summary>
/// <param name="attributes">The attributes in the configuration element.</param>
public void Configure(System.Collections.Specialized.StringDictionary attributes)
{
if (attributes.ContainsKey(AssemblyNameAttribute))
{
assemblyNameName = attributes[AssemblyNameAttribute];
}
}

#endregion

/// <summary>
/// Resolve the conflict in the selecction of Project or ProjectItem.
/// </summary>
/// <param name="target"></param>
/// <returns>
/// Return the normalized VSProject use to get the reference
/// </returns>
private VSProject GetProject(object target)
{
//If It is project
Project project = target as Project;

if (project != null)
return project.Object as VSProject;

//If It is project item
ProjectItem projectItem = target as ProjectItem;

if (projectItem != null)
return projectItem.ContainingProject.Object as VSProject;

//return default
return null;
}

}
}


And it is use in the <Recipe Name="BindingRecipe">:

<Action Name="FeeClassRef" Type="RefCreator" AssetName="FeeClass"
ReferenceType="Microsoft.Services.BF.GuidancePackage.References.ProjectAssemblyReference, Microsoft.Services.BF.GuidancePackage"
AssemblyReferenceName="Microsoft.Services.BF.FeesManagement"/>


The class take the target parameter, and verify if it is project or projectitem, recover the vsproject, for get the reference project.
Iterate by each reference and compare if it have the reference define in the AssemblyReferenceName attribute.

Many Thanks


Leandro Tuttini  Friday, September 28, 2007 1:27 PM

You can use google to search for other answers

Custom Search

More Threads

• GAX/GAT breaking DSL
• Successful installation - July Vista GAX GAT Software Factory
• Guidance Package Visual Studio 2005 Project Template not installed on Win XP Service Pack 2
• GAT for VS2008 installation issues
• installation problem in GAX
• GAX/GAT: February 2008 Final Release
• Target solution assemblies get loaded on the guidance package on runtime
• "Add new module" recipe customization
• Share arguments between recipes
• Change the solution path