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

Improved dotnet new ITEM templates context support #3829

Closed
9 of 10 tasks
Tracked by #4285
bekir-ozturk opened this issue Sep 1, 2021 · 5 comments
Closed
9 of 10 tasks
Tracked by #4285

Improved dotnet new ITEM templates context support #3829

bekir-ozturk opened this issue Sep 1, 2021 · 5 comments
Assignees
Labels
7.0 Cost:M Work that requires one engineer up to 2 weeks Priority:1 Work that is critical for the release, but we could probably ship without triaged The issue was evaluated by the triage team, placed on correct area, next action defined. User Story A single user-facing feature. Can be grouped under an epic.
Milestone

Comments

@bekir-ozturk
Copy link
Contributor

bekir-ozturk commented Sep 1, 2021

Background

This is about better item templates context support in dotnet new (evaluate MSBuild properties and namespace). Allows to get details of the project item template should be added to.
Details are:

  • namespace,
  • MSBuild properties.
    Limited to C# projects only.

Problem Summary

Item templates are limited now due to following reason:

No project context information when creating item templates

Though some item templates exist at the moment, they are barely usable as they are missing the context of the project they are being adding to. As the result, the simplest item template for class still cannot be implement as it is not possible to evaluate project namespace.

Design thoughts

  • introduce component-based way to evaluate project and its context with separate implementation for CLI and Visual Studio
  • supplement CLI to evaluate project context and feed the MS Build properties in addition to Visual Studio

Justification

  • ITEM templates relevance depends on context.
  • Restricting listing ITEM templates as available templates for given project context and being run if project context restrictions are not met.

Customer impact:

  1. Template authors will have a possibility to create item templates knowing key information about the project: namespace, tfm, etc.
  2. In addition to above, template authors will have a possibility to restrict item templates to be run only in certain type of projects (using project capability MSBuild property + constraints)
  3. Users will need to specify less information about item templates (now namespace needs to be specified etc).

Requirements

  1. Create a component-based approach to evaluate project context for item templates.
  2. Implement a way to determine project context for CLI templates.
  3. Implement constraint allowing to restrict templates based on ProjectCapabilities.
  4. Adapt dotnet new CLI to handle item templates
    1. Show only applicable item templates in dotnet new list
    2. Restrict non-applicable item templates for instantiation
    3. Provide a way to select the project to add item template to in case of ambiguity.

Prerequisite to...

Also fixes

Subtasks

  • PoC and design
  • implement project context find and MSBuild evaluation
  • implement constraint based on MSBuild ProjectCapability item
  • implement a way to pass through MSBuild properties as symbols
  • add a way to force using of the prefix to the source
  • pass-through output location - via dotnet/sdk
  • implement an option to specify the project in case of multiple options (?) - via dotnet/sdk
  • expression evaluation for capabilities
  • cleanup localization
@bekir-ozturk bekir-ozturk added triaged The issue was evaluated by the triage team, placed on correct area, next action defined. Epic Groups multiple user stories. Can be grouped under a theme. .NET 7 candidate labels Sep 1, 2021
@vlada-shubina vlada-shubina removed the Epic Groups multiple user stories. Can be grouped under a theme. label Sep 3, 2021
@vlada-shubina vlada-shubina changed the title Expose MSBuild properties as template symbols Item templates and expose MSBuild properties as template symbols Sep 14, 2021
@vlada-shubina vlada-shubina changed the title Item templates and expose MSBuild properties as template symbols Better item templates context support in dotnet new (evaluate MSBuild properties and namespace) Apr 4, 2022
@vlada-shubina vlada-shubina added the User Story A single user-facing feature. Can be grouped under an epic. label Apr 4, 2022
@vlada-shubina vlada-shubina modified the milestones: April 2022, Backlog Apr 4, 2022
@donJoseLuis donJoseLuis added 7.0 parent:1465551 Priority:1 Work that is critical for the release, but we could probably ship without Cost:M Work that requires one engineer up to 2 weeks and removed parent:1465551 labels Apr 5, 2022
@donJoseLuis
Copy link
Contributor

@donJoseLuis donJoseLuis changed the title Better item templates context support in dotnet new (evaluate MSBuild properties and namespace) Improved dotnet new ITEM templates context support Apr 5, 2022
@vlada-shubina vlada-shubina modified the milestones: Backlog, June 2022 May 4, 2022
@vlada-shubina vlada-shubina self-assigned this Jun 6, 2022
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Jul 12, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Jul 12, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
@vlada-shubina vlada-shubina modified the milestones: June 2022, July 2022 Jul 14, 2022
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Jul 21, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Jul 21, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Jul 21, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
@vlada-shubina vlada-shubina modified the milestones: July 2022, August 2022 Aug 1, 2022
vlada-shubina added a commit to vlada-shubina/sdk that referenced this issue Aug 2, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
vlada-shubina added a commit to dotnet/sdk that referenced this issue Aug 2, 2022
…ution

implemented constraint based on project capability/ies
implemented bind source for MSBuild properties
@vlada-shubina
Copy link
Member

The work is completed in RC1

@CesarD
Copy link

CesarD commented Mar 5, 2024

@vlada-shubina where are the docs for this? Been looking about these changes for days and I can't seem to find any references as the docs I can find are all messy and dispersed.

@baronfel
Copy link
Member

baronfel commented Mar 5, 2024

@CesarD take a look at the in-repo docs here: https://github.com/dotnet/templating/blob/main/docs%2FBinding-and-project-context-evaluation.md

@CesarD
Copy link

CesarD commented Mar 5, 2024

Thanks @baronfel. So for the solution name it's only possible to retrieve it if running the item template from Visual Studio? There's no chance to get the solution name from the dotnet new CLI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.0 Cost:M Work that requires one engineer up to 2 weeks Priority:1 Work that is critical for the release, but we could probably ship without triaged The issue was evaluated by the triage team, placed on correct area, next action defined. User Story A single user-facing feature. Can be grouped under an epic.
Projects
None yet
Development

No branches or pull requests

5 participants