How to create your own project templates in .NET

Поделиться
HTML-код
  • Опубликовано: 2 дек 2024

Комментарии • 71

  • @antibioticaddict
    @antibioticaddict 3 года назад +7

    It's so funny that I've been Googling this for the whole week and now you've come to my grace

    • @nickchapsas
      @nickchapsas  3 года назад +2

      It's almost like I perfectly planned it with the .NET release date :D

  • @allenn9068
    @allenn9068 28 дней назад

    Realize this is an older video but had a use case today for this. Spent the morning trying to create a multi-project template, the "old" way. That template export tool doesn't work well enough for solutions of any complexity, IMHO. Looked up the dotnet new template documentation, and found your video during that search. Microsoft should go a step further and mark the old way as obsolete for dotnet projects in their documentation. (Maybe I'll suggest it in a docs pull request). I now have a multiple project solution template, with references to infrastructure projects in shared folders, and loose files in solution folders. Made a template out of that solution after about 5 minutes of setup. Super fast, super awesome.

  • @doublebass120
    @doublebass120 3 года назад +6

    Thank you so much for this!! My Xamarin apps have a lot of boilerplate that I personally use, and this would save me SO MUCH time spinning up a new project!

  • @tanglesites
    @tanglesites 2 года назад

    For someone always starting projects, trying new things and learning new things, this is a life saver. I wasted no time and made my own. Now when I feel like I have found something I will use in every project, I put it in this template. Best video ever. QOL Game changer!🙃

  • @Ye3t572
    @Ye3t572 2 года назад +6

    Where is the documentation link😣

  • @react_33
    @react_33 2 года назад +4

    @*# syntax is not recognized (VS, VSC) any ideas?

  • @kwsanders
    @kwsanders 2 года назад +3

    @Nick Do you have the link for the documentation for templates? I did not see it in the description above.

  • @abhijithsugunan6768
    @abhijithsugunan6768 3 года назад +1

    Awesome, you just uploaded a video right when am looking for one.

  • @y0dasmydad
    @y0dasmydad 2 месяца назад +2

    Hi Nick. Any chance you could do an up to date version of this video? I have followed the video exactly and this no longer works :( I'm trying to create a template and failing miserably.

  • @cyrildouglas9262
    @cyrildouglas9262 3 года назад +5

    how about a multi-project template?

  • @HamishArb
    @HamishArb 3 года назад +6

    Wow, I'll be using that. 3 quick questions though, does it work with multiple projects in 1 template? What does it do with project names with spaces, because in some places you'd want to convert something like "My Project" to "My_Project", and in others you'd want to leave as-is. And how can you control the substitution on file names?

    • @wijanruiz1481
      @wijanruiz1481 3 года назад +3

      I'm interested in solution templates aswell, is that possible?

    • @hotshotcoding
      @hotshotcoding Год назад

      Yes it works, just create the .template.config folder at the solution level, not inside a project

  • @aspnano
    @aspnano 8 месяцев назад

    Nice video, covered all the key points

  • @sodiqyekeen7345
    @sodiqyekeen7345 2 года назад

    I have checked Microsoft doc for this and I couldn't get the details about this replacement approach. Thanks Nick...

  • @alfredoquintanalopez2265
    @alfredoquintanalopez2265 3 года назад

    This is great!!!! I needed a video like this. Thank you soo much!!!!!

  • @antoniocorreiadev
    @antoniocorreiadev 2 года назад +2

    Is it possible to conditionally add parameters? For example, depending on a selected choice a string parameter will be visible or not

    • @magorzatakurel3251
      @magorzatakurel3251 Год назад +3

      Yes, it's possible, when you create a template from the command line. But it doesn't work when you create a template from the wizard windows. Visual studio didn't implement it and I created a ticket for them with that, still waiting... :/

  • @migueltamarajaimes490
    @migueltamarajaimes490 5 месяцев назад

    Thank you Nick!!!!

  • @patrickkurmann
    @patrickkurmann 8 месяцев назад

    I like that you don't do stupid "RUclips face" as your thumbnail - based on the fact that your content is gold.

  • @VasoPerasLikodric
    @VasoPerasLikodric 3 года назад +1

    I might be crazy, but I did not figure out where did @Nick put link to documentation? I have tried to google for documentation but I am I am finding a proper documentation. Everything I have found is really short.

  • @Forshen
    @Forshen 9 месяцев назад

    hey, i can't find any info about, so i am gonna try it here. When i have the .template.config at solution dir, and i create a new solution/project from the template. The new solution does not get a project added. 0. When i put the .template.config inside the template project. it works great. But i wanna try to get multiple projects to my template. But I cant figure it out. You got any advise?

  • @HaydenHancock0
    @HaydenHancock0 2 года назад

    Any reason why the template wouldn't show up in the Visual Studio Create a new project window? I can create a project from CLI but I'd like to be able to select my template in the UI. Is that not possible without Rider?

  • @berkanbilgin2287
    @berkanbilgin2287 2 года назад +1

    Hey @Nick Chapsas Thanks for this... what about multiple projects in a template, like say I want to create a whole SOLID, repository pattern solution as a template? Would be great to share a video for that.

  • @jamesalcaraz8729
    @jamesalcaraz8729 Год назад

    Are you able to build the template project itself with all that parameterized entries, or do you need to generate a project form it to be able to test it?

  • @RootAndroidAndEthicalHacker
    @RootAndroidAndEthicalHacker 11 месяцев назад

    man i would love to see if you can make a video which uses different types of text templating engine like fluid, mustache , etc different libs and benchmark them to get results for doing same thing to know which is the best templating engine with fast efficient ,etc etc

  • @mou7866
    @mou7866 3 года назад +1

    Awesome video. I wanted a video on this topic. Maybe out of scope but any idea on how to create a solution template with 3 projects for example

    • @chanduwani89
      @chanduwani89 3 года назад

      Yes. you can create basic projects with reference along with solution file and place template folder on root. Try it.

  • @nachobolso06
    @nachobolso06 Год назад

    @*#if is not recognized and causes build to fail, any ideas? Using a .NET 6 WebApi project and I'm trying to put the conditional on the Program.cs.

  • @UmeshV
    @UmeshV 2 года назад

    Thank you so much for providing such an useful information. Any pointer for creating multi project templates.

  • @alexandertorres9758
    @alexandertorres9758 3 года назад

    My template project has git history. When I install the template, I also seem to bring over the git history. The result is running dotnet new mytemplate -0 "mynewapp" creates a new project but it contains the git history of the template. Is there a way for me to ignore the .git folder when installing the template?

  • @wdoering01
    @wdoering01 3 года назад

    wow that's reallly dope!!! thanks!!!!

  • @dewnoibkk
    @dewnoibkk 3 года назад

    Thank you for this video it helps me a lot. I'm having trouble with "#if DEBUG" syntax that it seems to be removed when I create a new project from the template, any work around?

  • @CodeThatVoid
    @CodeThatVoid 2 года назад

    Really good one :) thanks!

  • @bgrant1512
    @bgrant1512 8 месяцев назад

    Is there a way to share the templet outside of Nuget? My org. is not going to let me share via new get but Id like to distribute temples to my team.

    • @siredwin12
      @siredwin12 7 месяцев назад

      You can specify your own nuget source. That can be a local folder (but then sending updates to your team could be a problem) or your own nuget server hosted behind a VPN or something. This is what my team does. Then you and your team can add the nuget source in your IDE! Makes life so much easier. Otherwise, you'll probably need to make a git repo and your team can just pull the source and install locally as needed.

    • @bgrant1512
      @bgrant1512 7 месяцев назад +1

      @@siredwin12 The team has a mapped network drive , Ill try that. Thanks

  • @anotherme4638
    @anotherme4638 2 года назад

    Thank you so much, I got tired from writing the same code again and again. this video really helped me a lot
    I have a question : Is there a way to add/ remove package?
    Eg: In the Swagger example, is there a way to remove the package from the project (csproj) when the enable swagger choice is false ?

    • @buildingphase9712
      @buildingphase9712 Год назад

      Replace the entire line that installs swagger with nothing if the condition is not enabled.

  • @msashoyeb
    @msashoyeb 6 месяцев назад

    Life saver ❤❤

  • @ArmanOssiLoko
    @ArmanOssiLoko 3 года назад +4

    So I wasn't the only one to dislike Startup missing in the template. :)

    • @jarrichvdv
      @jarrichvdv 3 года назад +2

      It's a ridiculous decision.

    • @ArmanOssiLoko
      @ArmanOssiLoko 3 года назад +1

      ​@@jarrichvdv Couldn't agree more. When I tried creating an API project for test purposes, I saw a checkbox telling me it's for using minimal APIs.
      Basically, if you check it, it's gonna use the Minimal APIs template, and if you don't, it's supposed not to. When I unchecked it, I still wondered why I got a project with no Startup :/

    • @nickchapsas
      @nickchapsas  3 года назад +4

      Yeah even for me, that was a bit much

    • @HamishArb
      @HamishArb 3 года назад +1

      When I created a new console project, I was like "they even felt the need to change this one?"

    • @buffaloSoldier519
      @buffaloSoldier519 3 года назад

      So they removed startup alongside class templates?!

  • @aaronhevenstone9697
    @aaronhevenstone9697 2 года назад

    I just started learning templates for work and this video helped a bunch! I keep running into an issue though where the options aren't updating. when I do `-h` on my template, I can see the options, but their actual cli names (and shortname) are just not listed. Then when I try to use the options when calling dotnet new by assuming it's the first letter, I get a "not a valid option" error. This seems to happen randomly and only when my template file starts to grow a little. Have you had this issue before?

  • @coding-in
    @coding-in 2 года назад

    dotnet pack, it doesnt work for me raised error like this:
    .... error MSB4057: The target "pack" does not exist in the
    project.
    somebody could help?

  • @hedilberth
    @hedilberth Год назад

    Man I love you ❤ just the video I need it

  • @Orphen86
    @Orphen86 Год назад

    thanks excelent video, but I have s solution and two proyects, do you know how create de template.json?

  • @mahesh_rcb
    @mahesh_rcb 3 года назад

    Wow .
    Now that's a cool one 🙂

  • @TheKillingBoss
    @TheKillingBoss 3 года назад

    Is it possible to add content to *existing files* when applying an item template? (Example: a simple service implementation as a template and automatically adding it to Dependency Injection on creation)

    • @sayedha
      @sayedha 3 года назад +1

      Not with this technology

  • @shakib4845
    @shakib4845 2 года назад

    nice job!

  • @HiImKyle
    @HiImKyle 3 года назад

    The one thing I don't like when it comes to .NET 6 is that it seems, to me anyway, they're trying to be like JS/Python/(Insert other scripting language here) with the no class/namespace on the new templates, so thanks for this I'll be replacing all .NET 6 templates with my own that doesn't try to be something its not.

    • @nickchapsas
      @nickchapsas  3 года назад +1

      They are trying to remove some unnecessary boilerplate and make the language more accessible. I personally did not like that they removed the Startup.cs. I think having everything in the Program.cs is messy

    • @HiImKyle
      @HiImKyle 3 года назад +1

      I get the more accessible part, the unnecessary part I don't, but we're at completely different programming levels so I get the disconnect there. Just happy I can use a template to bring it all back.

  • @CeleChaudary
    @CeleChaudary 3 года назад +1

    Thanks for sharing content to us, master!!!

  • @argonjs
    @argonjs 3 года назад

    Hi.. Awesome video. Will this work also on visual studio for mac?

    • @igorthelight
      @igorthelight 3 года назад +2

      Why not?
      I don't see any platform specific code here.
      Unless Apple or Microsoft just want to be dicks.
      Again ;-)

    • @argonjs
      @argonjs 3 года назад

      @@igorthelight 😅 that's true. Will see

  • @krasnianskyi
    @krasnianskyi 3 года назад

    Hey, guys! How to we replace file scoped namespace with a regular one, if target framework is set to net5.0?

    • @nickchapsas
      @nickchapsas  3 года назад +1

      You have to add if checks to support both options

  • @agustinackermann6310
    @agustinackermann6310 3 года назад

    Thanks

  • @nfcradio4622
    @nfcradio4622 Год назад

    How to remove Template?

  • @princeowusu9854
    @princeowusu9854 Год назад

    🤣It's a little bit wired but it is what it is.

  • @micheleagnello7058
    @micheleagnello7058 Год назад

    This doesn't explain how you can create custom templates to have different auto generated content like razor pages for crud. This explains only how to put a unicorn in your namespace. WTF