Reputation: 3261
I am trying to create a project template in Visual Studio that has multiple projects within the solution.
In the main it works well and the only issue I am facing is referencing the other projects within the solution.
As you can see in the image the one project is referenced correctly as this path is set and not dynamic, the rest are all based off of the project name in the vstemplate file.
<VSTemplate Version="2.0.0" Type="ProjectGroup"
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name> Api Template</Name>
<Description>Base Template for Api Project</Description>
<Icon>Icon.ico</Icon>
<ProjectType>CSharp</ProjectType>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$projectname$.Api" CopyParameters="true">
Template.Api\Api.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$projectname$.Application" CopyParameters="true">
Template.Application\Appilication.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$projectname$.Infrastructure" CopyParameters="true">
Template.Infrastructure\Infrastructure.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$projectname$.Shared" CopyParameters="true">
Template.Shared\Shared.vstemplate
</ProjectTemplateLink>
<SolutionFolder Name="Common">
<ProjectTemplateLink ProjectName="Mediator.Common" CopyParameters="true">
Mediatr.Common\MediatorCommon.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="Common.Types" CopyParameters="true">
Common.Types\CommonTypes.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="Common.Http" CopyParameters="true">
Common.Http\HttpCommon.vstemplate
</ProjectTemplateLink>
</SolutionFolder>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
Next in the .csproj file where the references are being built up
<ItemGroup>
<ProjectReference Include="..\Mediator.Common\Mediator.Common.csproj" />
<ProjectReference Include="..\$projectname$.Application\$projectname$.Application.csproj" />
<ProjectReference Include="..\$projectname$.Infrastructure\$projectname$.Infrastructure.csproj" />
<ProjectReference Include="..\$projectname$.Shared\$projectname$.Shared.csproj" />
</ItemGroup>
This is trying to create the reference but I need it to drop the 'Api' from the middle.
I go this far from looking at this questions
Adding references in Visual Studio project template?
Using CustomParameter with Visual Studio Multi-Project Template
However, when looking here https://learn.microsoft.com/en-us/visualstudio/ide/template-parameters?view=vs-2019 when I try and add any other item in the reference is just wrong and is just shows as the $value$ rather than the project or anything else to do with it.
How can I refences the projects correctly so that the template I am creating doesnt need intervention immediately.
Upvotes: 0
Views: 975
Reputation: 3261
After much searching, trying failing I finally stumbled across this page
https://www.programmingwithwolfgang.com/create-a-net-core-visual-studio-template/
which then led me to the answer I was needing
<ItemGroup>
<ProjectReference Include="..\$ext_projectname$.Application\$ext_projectname$.Application.csproj" />
<ProjectReference Include="..\$ext_projectname$.Infrastructure\$ext_projectname$.Infrastructure.csproj" />
</ItemGroup>
I was missing the ext_ after the starting $
Upvotes: 3