Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds section documenting adding project references to existing projects #8019

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions docs/Post-Action-Registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,50 @@ Includes a reference to `SomeDependency` into `MyProjectFile`. The referenced pr
}]
```

## Adding references to existing projects

It is possible to add references to existing projects in your working directory. Since the name of the existing project is likely not a constant value for all template instantiations, a symbol can be used to pass the name of the existing project.

The example below demonstrates how to add the existing project ```src/AlreadyExisting/AlreadyExisting.csproj``` as a reference to the template source project ```Project1/Project1.csproj```.

```
{
"symbols": {
"existingProject": {
...
"type": "parameter",
"datatype": "string",
"defaultValue": "ExistingProject/ExistingProject.csproj",
"fileRename": "ExistingProjectPath" // Must be same as targetFile
}
},
"postActions": [
{
"Description": "Add ProjectReference to ExistingProject/ExistingProject.csproj",
"applyFileRenamesToArgs": [
"targetFiles" // Must be specified
],
"args": {
"targetFiles": [
"ExistingProjectPath" // Must be same as fileRename
],
"referenceType": "project",
"reference": "Project1/Project1.csproj"
}
}]
}
```

The template above:
- Configures the ```existingProject``` parameter *symbol* with a ```fileRename``` configuration.
- Instructs the *'add reference to a project file'* post action to apply ```fileRename``` to the ```targetFiles``` argument.
- Uses the value passed to the ```existingProject``` *symbol* to replace the value of the matching ```targetFiles```.

This template can be instantiated using:

```dotnet new [templateName] --existingProject src/AlreadyExisting/AlreadyExisting.csproj```


# Add project(s) to a solution file

- **Action ID** : `D396686C-DE0E-4DE6-906D-291CD29FC5DE`
Expand Down
Loading