Comments (3)
@phenning what's the syntax for getting the namespace in an item template?
from template-sample.
The Maui item templates are a good example of this:
https://github.com/dotnet/maui/tree/main/src/Templates/src/templates/maui-contentpage-csharp
In .cs file:
namespace AppName.Namespace;
in template.json:
"symbols": {
"namespace": {
"description": "Namespace for the generated code.",
"replaces": "AppName.Namespace",
"type": "parameter"
}
}
Visual Studio will recognize this symbol and automatically generate a safe namespace which includes the folder into which the template is being generated.
There is another syntax which is supported by the dotnet new as of NET 7 as well. Visual Studio also supports this, but it uses the msbuild RootNamespace property only instead of using the folder name in the namespace. This is documented here:
from template-sample.
Cool thanks, @sayedihashimi and @phenning.
from template-sample.
Related Issues (20)
- Doc update: how to add values to the dropdowns in VS
- Issue with package folder nesting HOT 1
- Create Blank Solution template HOT 3
- Create MSBuild task to run the analyzer
- Instantiating VS template with correct solution HOT 1
- How to ignore preprocessor configuration for dotnet template expanded code? HOT 3
- how to implement solution folders concept using templates HOT 1
- Warn when using guid format property
- dotnetnew.azurewebsites.net update schedule HOT 8
- HTTP Port not working correctly in Visual Studio for solution template HOT 14
- Remove source control configuration from generated projects HOT 4
- Item Templates Support HOT 5
- HostIdentifier symbol needs binding HOT 3
- Item Template Open File in Editor on Create HOT 7
- .net6 templates work from local folder, but the nuget package does not HOT 3
- VS is buggy when there is a problem with "framework" parameter HOT 7
- Visual Studio for Mac custom template Forms not showing HOT 17
- How to create the files conditionally using template.json HOT 3
- Renaming namespaces,Projects and namespaces with custom parameters. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from template-sample.