C
C#2y ago
Fright XO

❔ ✅ DotNet Templating Bind Project Name

With dotnet, there is a templating tool. It supports symbol replacement. With that you can bind to various properties. https://github.com/dotnet/templating/wiki/Binding-and-project-context-evaluation#bind-symbols I would like to get the project name. This would be whatever the developer submitted for their project name. There is a feature which replaces the project name, using the sourceName property, but this is a "safe" project name which uses _. I have tried many bindings I would expect to work but none do. msbuild:projectname context:projectname projectname targetname project name I also tried creating a derived symbol from the source name but I am unable to find the binding for the source name. Rider doesn't support custom parameter symbols so I want to avoid that for now since Rider is quite popular among my developer audience.
GitHub
Binding and project context evaluation · dotnet/templating Wiki
This repo contains the Template Engine which is used by dotnet new - Binding and project context evaluation · dotnet/templating Wiki
11 Replies
Anton
Anton2y ago
Anton
Anton2y ago
it's just name when you create a new project, you pass that as a parameter is this what you mean? I think it worked with just name
Fright XO
Fright XO2y ago
What you have as 'name' is the symbol name. Your behavior is using the type parameter and getting the user to type in the name. Rider doesn't support that functionality, so i'd like to use type bind and get it from a existing property. dotnet new and visual studio do support parameters, but all the devs i'll work with on these projects are using rider, from what i've gathered. So I'm really just trying to optimize developer experience.
Anton
Anton2y ago
yeah like you want that parameter to automatically bind to the project name right?
Fright XO
Fright XO2y ago
One option that exists may be to use the .vstemplate, i guess. https://learn.microsoft.com/en-us/visualstudio/ide/template-parameters?view=vs-2022 but i suspected all those replacement properties exist in this other templating
Project and item template parameters - Visual Studio (Windows)
Learn how to use template parameters to replace values in your template when the template is instantiated.
Anton
Anton2y ago
which I think it does i might be wrong
Fright XO
Fright XO2y ago
The users of that template get an additional field called "name" that gets a parameter though, right? I can try again, maybe parameter of type "name" gets automatically assigned?
Anton
Anton2y ago
they do, but it also gets autobound if you don't provide it, from the project name i think
Fright XO
Fright XO2y ago
parameters are usually custom fields on the template generation, was my understanding... trying now !!! you're awesome... i didn't know they also "bind" parameters... that worked :D
Anton
Anton2y ago
nice
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server