Project references in GAT

Yesterday I spent more or less the entire day trying to figure out how to add references between projects while unfolding a solution template. Turns out it was wasn’t that tricky once you get the hang of GAT… Here’s a step-by-step instruction:

  1. Add new arguments for the complete name of each project in the CreateSolution recipe:
    <Argument Name="BaseNamespace">
    <Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.NamespaceStringConverter, Microsoft.Practices.RecipeFramework.Library"/>
    <Argument Name="ServiceName" Type="System.String"/>
    <Argument Name="RootNamespace">
    <Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.NamespaceStringConverter, Microsoft.Practices.RecipeFramework.Library"/>
    <ValueProvider Type="Evaluator"
    <MonitorArgument Name="ServiceName" />
    <MonitorArgument Name="BaseNamespace" />
    <Argument Name="BusinessEntitiesProjectName">
    <ValueProvider Type="Evaluator"
    <MonitorArgument Name="RootNamespace" />
    <Argument Name="DataAccessProjectName">
    <ValueProvider Type="Evaluator"
    <MonitorArgument Name="RootNamespace" />

    As you can see, the project names are created automatically when specifying a root namespace and a service name – but that isn’t necessary for the solution to work.

  2. In the Solution.vstemplate file, make sure to pass the arguments on as custom parameters:
    <ProjectTemplateLink ProjectName="$BusinessEntitiesProjectName$">Projects\BusinessEntities\BusinessEntities.vstemplate</ProjectTemplateLink>
    <ProjectTemplateLink ProjectName="$DataAccessProjectName$">Projects\DataAccess\DataAccess.vstemplate</ProjectTemplateLink>
    <CustomParameter Name="$BusinessEntitiesProjectName$" Value="$BusinessEntitiesProjectName$"/>
    <CustomParameter Name="$DataAccessProjectName$" Value="$DataAccessProjectName$"/>
  3. Do the same for each project .vstemplate file:
    <CustomParameter Name="$businessentitiesprojectname$" Value="$BusinessEntitiesProjectName$"/>
    <CustomParameter Name="$dataaccessprojectname$" Value="$DataAccessProjectName$"/>
  4. And finally, in the project where you want to add a reference, put a new ItemGroup that looks like this:
    <ProjectReference Include="..\$businessentitiesprojectname$\$businessentitiesprojectname$.csproj">

Oh, and there is an added bonus. If you use the same namespace names as project names, you can put things like this in any pre-generated content:

using $businessentitiesprojectname$;

One response to “Project references in GAT”

  1. Thanks so much for this… it was a big help!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About Me

Consultant, Solution Architect, Developer.

Do note that this blog is very, very old. Please consider that before you follow any of the advice in here!


%d bloggers like this: