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:
- Add new arguments for the complete name of each project in the CreateSolution recipe:
<Arguments>
<Argument Name="BaseNamespace">
<Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.NamespaceStringConverter, Microsoft.Practices.RecipeFramework.Library"/>
</Argument>
<Argument Name="ServiceName" Type="System.String"/>
<Argument Name="RootNamespace">
<Converter Type="Microsoft.Practices.RecipeFramework.Library.Converters.NamespaceStringConverter, Microsoft.Practices.RecipeFramework.Library"/>
<ValueProvider Type="Evaluator"
Expression="$(BaseNamespace).$(ServiceName)">
<MonitorArgument Name="ServiceName" />
<MonitorArgument Name="BaseNamespace" />
</ValueProvider>
</Argument>
<Argument Name="BusinessEntitiesProjectName">
<ValueProvider Type="Evaluator"
Expression="$(RootNamespace).BusinessEntities">
<MonitorArgument Name="RootNamespace" />
</ValueProvider>
</Argument>
<Argument Name="DataAccessProjectName">
<ValueProvider Type="Evaluator"
Expression="$(RootNamespace).DataAccess">
<MonitorArgument Name="RootNamespace" />
</ValueProvider>
</Argument>
...
</Arguments>
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.
- In the Solution.vstemplate file, make sure to pass the arguments on as custom parameters:
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$BusinessEntitiesProjectName$">Projects\BusinessEntities\BusinessEntities.vstemplate</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$DataAccessProjectName$">Projects\DataAccess\DataAccess.vstemplate</ProjectTemplateLink>
</ProjectCollection>
<CustomParameters>
<CustomParameter Name="$BusinessEntitiesProjectName$" Value="$BusinessEntitiesProjectName$"/>
<CustomParameter Name="$DataAccessProjectName$" Value="$DataAccessProjectName$"/>
</CustomParameters>
</TemplateContent>
- Do the same for each project .vstemplate file:
<CustomParameters>
<CustomParameter Name="$businessentitiesprojectname$" Value="$BusinessEntitiesProjectName$"/>
<CustomParameter Name="$dataaccessprojectname$" Value="$DataAccessProjectName$"/>
- And finally, in the project where you want to add a reference, put a new ItemGroup that looks like this:
<ItemGroup>
<ProjectReference Include="..\$businessentitiesprojectname$\$businessentitiesprojectname$.csproj">
<Name>$businessentitiesprojectname$</Name>
</ProjectReference>
</ItemGroup>
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$;
Posted
Jan 05 2006, 11:58 AM
by
anders