|
1 | 1 | ---
|
2 | 2 | title: Create multi-project templates
|
3 | 3 | description: Create multi-project templates in Visual Studio that can act as containers for many projects at the same time and containers for projects of different languages.
|
4 |
| -ms.date: 04/17/2019 |
| 4 | +ms.date: 04/05/2024 |
5 | 5 | ms.topic: how-to
|
6 | 6 | helpviewer_keywords:
|
7 | 7 | - Visual Studio templates, creating multi-project
|
@@ -185,6 +185,65 @@ This example uses the **SolutionFolder** element to divide the projects into two
|
185 | 185 | </VSTemplate>
|
186 | 186 | ```
|
187 | 187 |
|
| 188 | +## Example with project references |
| 189 | + |
| 190 | +This example shows how to add project references to a multi-project template and is essentialy an extension of the [multi-project template](#create-multi-project-templates) example. |
| 191 | + |
| 192 | +In this example the solution contains two projects, **MultiProject.Client** and **MultiProject.Shared**. The project **MultiProject.Client** references **MultiProject.Shared**. |
| 193 | + |
| 194 | +The folder structure is as follows: |
| 195 | + |
| 196 | +- *MultiProjectTemplate.vstemplate* |
| 197 | +- *\MultiProject.Client\MultiProject.Client.csproj* |
| 198 | +- *\MultiProject.Client\MyTemplate.vstemplate* |
| 199 | +- *\MultiProject.Shared\MultiProject.Shared.csproj* |
| 200 | +- *\MultiProject.Shared\MyTemplate.vstemplate* |
| 201 | + |
| 202 | +When the template is used the *MultiProject* part is being replaced with the project name the user enters. |
| 203 | + |
| 204 | +The *MultiProjectTemplate.vstemplate* looks like the following. Please note that the *ProjectTemplateLink*s have the attribute **CopyParameters** set to *true* and that the **ProjectName** attributes use the template variable [\$safeprojectname\$](./template-parameters.md#reserved-template-parameters). |
| 205 | + |
| 206 | +```xml |
| 207 | +<VSTemplate Version="2.0.0" Type="ProjectGroup" |
| 208 | + xmlns="http://schemas.microsoft.com/developer/vstemplate/2005"> |
| 209 | +... |
| 210 | +<TemplateContent> |
| 211 | + <ProjectCollection> |
| 212 | + <ProjectTemplateLink ProjectName="$safeprojectname$.Client" CopyParameters="true"> |
| 213 | + MultiProject.Client\MyTemplate.vstemplate |
| 214 | + </ProjectTemplateLink> |
| 215 | + <ProjectTemplateLink ProjectName="$safeprojectname$.Shared" CopyParameters="true"> |
| 216 | + MultiProject.Shared\MyTemplate.vstemplate |
| 217 | + </ProjectTemplateLink> |
| 218 | + </ProjectCollection> |
| 219 | +</TemplateContent> |
| 220 | +</VSTemplate> |
| 221 | +``` |
| 222 | + |
| 223 | +The *MultiProject.Client\MyTemplate.vstemplate* might look something like the following. Please note that the *Project* tag has the attribute **ReplaceParameters** set to *true*. |
| 224 | + |
| 225 | +```xml |
| 226 | +<VSTemplate Version="3.0.0" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005" Type="Project"> |
| 227 | + ... |
| 228 | + <TemplateContent> |
| 229 | + <Project TargetFileName="MultiProject.Client.csproj" File="MultiProject.Client.csproj" ReplaceParameters="true"> |
| 230 | + ... |
| 231 | + </Project> |
| 232 | + </TemplateContent> |
| 233 | +</VSTemplate> |
| 234 | +``` |
| 235 | + |
| 236 | +The *MultiProject.Client\MultiProject.Client.csproj* might look something like the follwoing. Please note that the attribute **Include** of the *ProjectReference* uses the template variable [\$ext_safeprojectname\$](./template-parameters.md#reserved-template-parameters) |
| 237 | + |
| 238 | +```xml |
| 239 | +<Project> |
| 240 | + ... |
| 241 | + <ItemGroup> |
| 242 | + <ProjectReference Include="..\$ext_safeprojectname$.Shared\$ext_safeprojectname$.Shared.csproj" /> |
| 243 | + </ItemGroup> |
| 244 | +</Project> |
| 245 | +``` |
| 246 | + |
188 | 247 | ## Related content
|
189 | 248 |
|
190 | 249 | - [Creating project and item templates](../ide/creating-project-and-item-templates.md)
|
|
0 commit comments