-
Notifications
You must be signed in to change notification settings - Fork 329
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
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🦙❤️ 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh YES! This is such a nice cleanup of the starter template! Ship it!
Also regarding the readme discussion. Please don't add junk to the project structure. This might be better as a Visual Studio feature, with the little yellow tips bar that is sometimes on top of the file tabs (I've seen MAUI often use this)
Leaving this here for the future, @niels9001 found the introduction to start pages in VS blog here: https://devblogs.microsoft.com/visualstudio/walkthrough-creating-a-custom-start-page-part-1/ Seems like we should create follow-on tasks for both WPF and WinUI here (for both C++ and C#) to work to adding these into the templates. |
I haven't seen this mentioned here but the default .NET .editorconfig file defines block scoped namespace so Visual Studio or other tools using .editorconfig may format using block scoped. csharp_style_namespace_declarations = block_scoped Just letting my thoughts since I don't see this being addressed. Nothing that I think this PR can do since this is more of a Visual Studio problem than WASDK. |
Hi @michael-hawker |
Absolutely correct |
@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.csWindowsAppSDK/dev/VSIX/Extension/Cs/Dev17/WindowsAppSDK.Cs.Extension.Dev17.csproj Line 14 in bc1af23
If 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? WindowsAppSDK/dev/VSIX/Extension/Cpp/Dev17/WindowsAppSDK.Cpp.Extension.Dev17.csproj Line 82 in bc1af23
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). |
Purpose
Regarding to #3329, creating this PR to introduce file scoped namespaces.
What have changed
For all .cs files inside
dev/VSIX/ItemTemplates
anddev/VSIX/ProjectTemplates
, the template code format have been changed to file scoped namespaces: