Update C# templates to introduce file scoped namespaces#4911
Conversation
|
1 more thing to be confirmed: |
I'm not as familiar with those, but it doesn't hurt to apply this change to every C# file across the entire repo. File-scoped namespaces were added for .NET 6, which should be everything here. |
michael-hawker
left a comment
There was a problem hiding this comment.
🦙❤️ Awesome, thanks @haonanttt for putting this together! 🎉🎉🎉 Couple of suggestions to improve partial class coverage for AOT and source generators.
I thought I remembered another small thing related to templates, but can't find it in my chat history. Nothing came to mind when going through the review. @niels9001 want to do a quick pass to see if I missed anything?
dev/VSIX/ItemTemplates/Neutral/CSharp/TemplatedControl/CustomControl.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/ClassLibrary/Class1.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/BlankApp/MainWindow.xaml.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/SingleProjectPackagedApp/MainWindow.xaml.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/UnitTestApp/UnitTests.cs
Outdated
Show resolved
Hide resolved
…hared folders as well
1. mark all classes 'partial' 2. align the MainWindow to be an empty Grid without the Button and handler
|
@haonanttt Love these changes 🚀! Since we are removing the Button click event, we should remove it from the With .NET9 WPF now comes with modern theming and has |
dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/BlankApp/MainWindow.xaml.cs
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/SingleProjectPackagedApp/MainWindow.xaml
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/BlankApp/MainWindow.xaml
Show resolved
Hide resolved
|
@niels9001 good call out! This may have been what I was thinking about unconsciously. It was pretty jarring to see the difference with the new WPF template/theming enabled and the WinUI window just being a black box during our .NET Conf demo: |
@microsoft-github-policy-service agree company="Microsoft" |
dev/VSIX/ItemTemplates/Neutral/CSharp/UserControl/UserControl.xaml
Outdated
Show resolved
Hide resolved
|
Current changes:
Need discussion:
|
dev/VSIX/ProjectTemplates/Desktop/CSharp/SingleProjectPackagedApp/MainWindow.xaml
Show resolved
Hide resolved
2. Remove Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" from Blank Page item template
michael-hawker
left a comment
There was a problem hiding this comment.
Looking great! Just did a quick pass to apply some C# style guidelines as suggestions which can be applied in batch. Mostly to remove this. and the m_ to just _ for window. (I linked to references in those first comments.) The only thing I couldn't make as a suggest was moving the _window member to the top of the class.
Thanks so much for going through this with us, this is going to be a great improvement to the templates to make it more streamlined for devs to get work done! 🦙❤️
dev/VSIX/ItemTemplates/Desktop/CSharp/BlankWindow/BlankWindow.xaml.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ItemTemplates/Neutral/CSharp/BlankPage/BlankPage.xaml.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ItemTemplates/Neutral/CSharp/TemplatedControl/CustomControl.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ItemTemplates/Neutral/CSharp/UserControl/UserControl.xaml.cs
Outdated
Show resolved
Hide resolved
dev/VSIX/ProjectTemplates/Desktop/CSharp/PackagedApp/BlankApp/MainWindow.xaml.cs
Outdated
Show resolved
Hide resolved
2. Add empty line between functions
|
Current status:
Next steps:
|
|
FYI @Scottj1s, Niels and I are all good here as external approvers; we really appreciate the work @haonanttt has done with us here to modernize the templates and bring them up-to-date with all the latest .NET features/patterns. 🦙❤️ I believe we addressed @codendone's initial concern about the Button in the comment thread, but happy to chat about any concerns you have, feel free to ping me if you have any - otherwise hopefully we can just merge. Thanks! |
|
@haonanttt I'll add my thanks too, as well as to @mrlacey, @dotMorten, who were involved in an earlier discussion on this, and to @wjk, who authored a similar PR a few years ago, later closed. I appreciate the need for discussion, but we clearly never got around to one, and the frustrations remain. My preference is to bias for action here and course correct if necessary. A few things to consider:
|
Ah, wasn't paying close attention - I see we've removed Button across the board |
|
@Scottj1s I like the idea of a readme, but I know for UWP VS would just pop open the 'getting started' guide when you started a new project to get these resources: They do have this comment in the MainPage.xaml.cs:
For WinUI 3 by comparison, that 'getting started' guide does not appear - are we missing a flag or something - or was this just never ported over in VS? And we already have this comment in the MainWindow.xaml.cs file:
But this landing page is a bit sparse, should we use a different aka.ms link here or improve that doc page? FYI @niels9001 |
|
@Scottj1s could we merge these technical improvements into the templates now? And then take a follow-up with a task to talk about improving the getting started pages in VS across the board? It seems that may be unique to UWP, but a great feature. Like WPF doesn't do it either and just throws you into MainWindow.xaml: Our other templates don't add readmes (as then folks tend to never go update those so we could get repos people push to GitHub that just have that file everywhere muddling search results). It really seems to be supplanting this feature that seems supported by VS somehow/somewhere for at least some project types, so it'd be great if we could work to improve this everywhere for everyone for all project types working across the VS ecosystem. And in the interim, we should update the existing link's comment or improve the page it points to in the docs. @niels9001 is that a good aka.ms link which of those two comment options should we take? |
|
@haonanttt @Scottj1s now that we have this approved, what's left before we merge? How do these get integrated into releases from the repo here? Will it just be in the next latest drop on NuGet that pulls these in? |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
Looks like some of the auxiliary project types target older .NET runtimes or something?
dev\VSIX\Extension\Cs\Dev17\VSPackage.csIf this is just for the package itself, we should be fine to just add dev\VSIX\Shared\WizardImplementation.csThe same csproj above manages this file as well, though there's also an include of it in the C++ project as well? Not as sure what this even means here. If these are just internal files to the VSIX, we don't have to update the scope here, or we can try adding |
|
Investigated and informed the file |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
🦙❤️ Thanks @haonanttt! This is great! 🎉🎉🎉 |
* Update C# templates to introduce file scoped namespaces
* introduce file scoped namespaces to dev/VSIX/Extension and dev/VSIX/Shared folders as well
* resolve comments:
1. mark all classes 'partial'
2. align the MainWindow to be an empty Grid without the Button and handler
* Enable Mica
* remove mica for non-window level
* 1. Remove 'Button' from C++ templates
2. Remove Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" from Blank Page item template
* 1. Remove 'this.' and change 'm_' to '_'
2. Add empty line between functions
* revert file scoped namesapce for VSPackages.cs and WizardImplementation.cs
---------
Co-authored-by: Haonan Tang (from Dev Box) <haonantang@microsoft.com>
|
Is the |
|
@haonanttt I just downloaded VS 17.14 Preview 3, I see some of the template changes, but not all of them. The file-scoped namespaces for instance aren't there...? But I see them in |




Purpose
Regarding to #3329, creating this PR to introduce file scoped namespaces.
What have changed
For all .cs files inside
dev/VSIX/ItemTemplatesanddev/VSIX/ProjectTemplates, the template code format have been changed to file scoped namespaces: