Skip to content

Conversation

licon4812
Copy link
Contributor

@licon4812 licon4812 commented Aug 16, 2023

Summary

Added sourceName information to the create-item and create-project cli tutorials as it is an essential property when creating dotnet cli templates


Internal previews

📄 File 🔗 Preview link
docs/core/tutorials/cli-templates-create-item-template.md Tutorial: Create an item template
docs/core/tutorials/cli-templates-create-project-template.md Create a project template for dotnet new

@licon4812 licon4812 requested a review from tdykstra as a code owner August 16, 2023 08:53
@dotnet-bot dotnet-bot added this to the August 2023 milestone Aug 16, 2023
@ghost ghost added the community-contribution Indicates PR is created by someone from the .NET community. label Aug 16, 2023
@tdykstra
Copy link
Contributor

@adegeo Please review.

@adegeo adegeo self-assigned this Aug 17, 2023
@adegeo adegeo added the 🗺️ reQUEST Triggers an issue to be imported into Quest. label Aug 29, 2023
@adegeo
Copy link
Contributor

adegeo commented Sep 6, 2023

Thank you for this submission! I've added a few corrections and suggestions. I think the item template article doesn't need this at all.

@licon4812 licon4812 requested a review from adegeo September 6, 2023 21:23
@licon4812
Copy link
Contributor Author

Thank you for this submission! I've added a few corrections and suggestions. I think the item template article doesn't need this at all.

@adegeo

The sourceName doesn't just work with the project templates it is also used for items as well. So that the namespace and class file name is set based on user input

@BillWagner BillWagner modified the milestones: August 2023, September 2023 Sep 7, 2023
@adegeo
Copy link
Contributor

adegeo commented Sep 7, 2023

The namespace must be System because it's an extension method. However, I think at the time I was more hung up on "namespace..." really this could be used for the class name and file name of the class. I'll update those to match in your PR and approve this. Thanks!

@adegeo
Copy link
Contributor

adegeo commented Sep 7, 2023

Actually, I was just playing around with this and I don't think it makes sense for the item template. If the user doesn't provide a name, the class name and file name both get created with the same name as the folder. That isn't really a good experience. For the project template, this value makes 100% sense. But not in the item template. Really this needs an optional variable that you could pass into the template.

@adegeo
Copy link
Contributor

adegeo commented Sep 7, 2023

OK I looked it up and figured out how to do optional template parameters. It's a big more complicated and requires some more explanation in the article. I actually happen to be working on updating these articles this week (with more modern C# code and other little fixes). If you would like, I can add that stuff to my rewrites. We could just remove the item template content from this PR and push through the project template updates. How does that sound? Or you could update the article too 😁 Let me know what you want to do.

The code for the template is:

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Me",
    "classifications": [ "Common", "Code" ],
    "identity": "ExampleTemplate.StringExtensions",
    "name": "Example templates: string extensions",
    "shortName": "stringext",
    "tags": {
      "language": "C#",
      "type": "item"
    },
    "symbols": {
      "ClassName":{
        "type": "parameter",
        "description": "The name of the code file and class.",
        "datatype": "text",
        "replaces": "StringExtensions",
        "fileRename": "StringExtensions",
        "defaultValue": "StringExtensions"
      }
    }
  }

And you'll need to explain that section. You can see what parameters are allowed with the following command:

dotnet new stringext -?
Example templates: string extensions (C#)
Author: Me

Usage:
  dotnet new stringext [options] [template options]

Options:
  -n, --name <name>       The name for the output being created. If no name is specified, the name of the output directory is used.
  -o, --output <output>   Location to place the generated output.
  --dry-run               Displays a summary of what would happen if the given command line were run if it would result in a template creation.
  --force                 Forces content to be generated even if it would change existing files.
  --no-update-check       Disables checking for the template package updates when instantiating a template.
  --project <project>     The project that should be used for context evaluation.
  -lang, --language <C#>  Specifies the template language to instantiate.
  --type <item>           Specifies the template type to instantiate.

Template options:
  -C, --ClassName <ClassName>  The name of the code file and class.
                               Type: text
                               Default: StringExtensions

@licon4812
Copy link
Contributor Author

@adegeo Thank you for the feedback. I have modified the explanation of the create-item-template to match the information you have provided.

I figured we should both item and project template files in this PR to avoid having multiple PRs for only 2 files.

Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@adegeo adegeo merged commit 82ccf32 into dotnet:main Sep 8, 2023
@licon4812 licon4812 deleted the dotnet-cli-templates branch September 8, 2023 22:14
IEvangelist pushed a commit to IEvangelist/docs that referenced this pull request Oct 2, 2023
* added sourceName info: create-item & project tuts

* Update docs/core/tutorials/cli-templates-create-project-template.md

Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com>

* Updated cli-templates-create-item-template.md

* Updated cli-temlates-create-item-template.md

* updated create-item-template to have ClassName optional

---------

Co-authored-by: Andy (Steve) De George <67293991+adegeo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates PR is created by someone from the .NET community. dotnet-fundamentals/svc 🗺️ reQUEST Triggers an issue to be imported into Quest.

Projects

No open projects
Status: 👀 In review

Development

Successfully merging this pull request may close these issues.

5 participants