rsaz / csharp-snippet-productivity

The complete snippet toolbox for C#"
MIT License
19 stars 6 forks source link

"C# Toolbox: Create Class" not respecting <RootNamespace> tag in .csproj #1

Closed Shekesh closed 3 years ago

Shekesh commented 3 years ago

Hello, first, thank you very much for this great extension.

Working with it I noticed a thing missing with the C# Toolbox: Create Class context menu item. The function behind this action seems to always use the root folder name as the base of the namespace for a new class. When in the *.csproj-file a <RootNamespace> is defined I would expect that this is used instead as the namespace base.

rsaz commented 3 years ago

Hi @Shekesh thank you for reaching out. Questions and observations such yours, helps me to improve the extension. You are correct on your observation. When using VS Community for C# .net core it creates your .csproj with tons of properties and one of them are Your.Namespace Which always correspond to the name of your project folder. I understand that in some cases we need to have different names among project folder name and main root namespace placed in the RootNamepsace tag inside of .csproj. I just would like to point out is that when you create a new .net core project within vscode, the .csproj have a small footprint internal structure which doesn't include tag. What I will do is, when creating classes or interface I will look at inside of the .csproject if you have your Root tag to consider as your namespace root, otherwise it will look at your project folder, how that sounds?

Shekesh commented 3 years ago

Hi @rsaz, that sounds perfect for me. It's exactly as you describe that I intentionally set the RootNamespace tag to have a different namespace then the root folder because I usually put my code into an src folder which results in a src. namespace. Thank you very much

rsaz commented 3 years ago

Hi @Shekesh I just updated the extension implementing the enhancement suggested by you. Version 1.2.2 https://github.com/rsaz/csharp-snippet-productivity

Enhancement: When creating classes or interfaces system will consider if you have a <RootNamespace>YourUniqueNamespace</RootNamespace> tag on your .csproj. If the tag is not found system will use your project name as your root namespace

Thank you for your suggestion.