-
Notifications
You must be signed in to change notification settings - Fork 369
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
Improve root namespace definition for templates #6010
Comments
Yes, the namespace needs to get synced with the containing folder name included (relative to the project file). For example, namespace MyApp;
public class BaseViewModel
{
} |
We |
Any updates on that ? |
I have a sample of a Class template which gets the projects rootnamespace and uses that as the namespace declaration. Sample is at https://github.com/sayedihashimi/template-sample/blob/main/src/contoso-templatepack/content/item-templates/classfile/.template.config/template.json, I've pasted the template.json below. This doesn't solve adding the relative folder path though. I believe this only works with .net 8+ but could be wrong on that. @baronfel will know which version the support is in. {
"$schema": "http://json.schemastore.org/template",
"$comment": "Code for this template is available at https://github.com/sayedihashimi/template-sample",
"author": "Contoso",
"classifications": ["template"],
"name": "contoso-class",
"description": "Contoso item template for a class file with a Contoso approved license.",
"identity": "Contoso.Templates.Item.ClassWithLicense",
"shortName": "cclass",
"tags": {
"language": "C#",
"type": "item"
},
"sourceName": "SampleClassFile",
"defaultName": "MyClass",
"symbols": {
"DefaultNamespace": {
"type": "bind",
"binding": "msbuild:RootNamespace",
"replaces": "Contoso.Starter",
"defaultValue": "Contoso"
}
},
"primaryOutputs": [
{
"path": "SampleClassFile.cs"
}
],
"postActions": [
{
"id": "openInEditor",
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"description": "Opens generated files in the editor",
"manualInstructions": [],
"actionId": "84C0DA21-51C8-4541-9940-6CA19AF04EE6",
"args": {
"files": "0"
},
"continueOnError": true
}
]
} In the sample above you can see the DefaultNamespace symbol which replaces the string |
@sayedihashimi While using the parameter For example, assume Kindly look into it. |
Thanks, yes we will need to figure out a way to get the relative folder path into the generated namespace. I will discuss with the team to see what options we have. |
How to get the current path of the "dotnet new" while processing the template, like the Need the current directory while processing an item template. Any possibility of using Any input would be highly appreciated. |
A few of us discussed this today. Unfortunately @baronfel was unavailable for that discussion, but we will need to sync with him as well. Below is a brief summary of what we discussed and the two options that were most obvious. Proposal 1
Pros
Cons
Proposal 2
Pros
Cons
|
meanwhile could we do something e.g. using postActions? |
Is this issue dead? This is REALLY annoying, mostly when starting a new project. |
This is really annoying. What has been helping me is the 'C# Extensions v1.7.3'; it can fetch the namespace normally... |
Is your feature request related to a problem? Please describe.
Feature request
Describe the solution you'd like.
Based on Consider adding a class item template #1713
Additional context
No response
The text was updated successfully, but these errors were encountered: