unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
9.07k stars 735 forks source link

New Page Should use semi-colon namespace without the folder name #12159

Open elibroftw opened 1 year ago

elibroftw commented 1 year ago

What would you like to be added:

When create a new blank page using the uno template, it'll produce the following output:

namespace App.Views {
    public sealed partial class NavigationPage : Page {
        public NavigationPage() {
            this.InitializeComponent();
        }
    }
}

This causes bugs when building related to "InitializeComponent" . What I want is


namespace App; 

public sealed partial class NavigationPage : Page {
    public NavigationPage() {
        this.InitializeComponent();
    }
}

Why is this needed:

For which Platform:

Anything else we need to know?

Youssef1313 commented 1 year ago

This causes bugs when building related to "InitializeComponent"

Can you clarify more?

Can you also try adding csharp_style_namespace_declarations = file_scoped to .editorconfig?

elibroftw commented 1 year ago

Yes I can clarify more, here is the output when building if a BlankPage is created. .editorconfig change had no impact.

output------ Rebuild All started: Project: SplitTheTankApp, Configuration: Debug Any CPU ------ 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,33,22,43): warning UXAML0002: SplitTheTankApp.Views.BlankPage1 does not explicitly define the Microsoft.UI.Xaml.Controls.Page base type in code behind. 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(11,23,11,27): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(12,23,12,28): error CS0234: The type or namespace name 'Input' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(13,23,13,28): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(14,23,14,33): error CS0234: The type or namespace name 'Navigation' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,46,22,50): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) 1>Done building project "SplitTheTankApp.csproj" -- FAILED. 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,33,22,43): warning UXAML0002: SplitTheTankApp.Views.BlankPage1 does not explicitly define the Microsoft.UI.Xaml.Controls.Page base type in code behind. 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(11,23,11,27): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(12,23,12,28): error CS0234: The type or namespace name 'Input' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(13,23,13,28): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(14,23,14,33): error CS0234: The type or namespace name 'Navigation' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,46,22,50): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,33,22,43): warning UXAML0002: SplitTheTankApp.Views.BlankPage1 does not explicitly define the Microsoft.UI.Xaml.Controls.Page base type in code behind. 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(11,23,11,27): error CS0234: The type or namespace name 'Data' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(12,23,12,28): error CS0234: The type or namespace name 'Input' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(13,23,13,28): error CS0234: The type or namespace name 'Media' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(14,23,14,33): error CS0234: The type or namespace name 'Navigation' does not exist in the namespace 'Windows.UI.Xaml' (are you missing an assembly reference?) 1>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp\Views\BlankPage1.xaml.cs(22,46,22,50): error CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?) 1>Done building project "SplitTheTankApp.csproj" -- FAILED. 2>------ Rebuild All started: Project: SplitTheTankApp.Mobile, Configuration: Debug Any CPU ------ 2>CSC : error UXAML0001: The type {using:SplitTheTankApp}App could not be found 2>CSC : error UXAML0001: Processing failed for file C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp.Base\AppHead.xaml (System.InvalidOperationException: The type {using:SplitTheTankApp}App could not be found 2>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp.Base\AppHead.xaml.cs(15,43,15,46): error CS0246: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) 2>Done building project "SplitTheTankApp.Mobile.csproj" -- FAILED. 2>CSC : error UXAML0001: The type {using:SplitTheTankApp}App could not be found 2>CSC : error UXAML0001: Processing failed for file C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp.Base\AppHead.xaml (System.InvalidOperationException: The type {using:SplitTheTankApp}App could not be found 2>C:\Users\maste\Documents\GitHub\SplitTheTankApp\SplitTheTankApp\SplitTheTankApp.Base\AppHead.xaml.cs(15,43,15,46): error CS0246: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?) 2>Done building project "SplitTheTankApp.Mobile.csproj" -- FAILED. ========== Rebuild All: 0 succeeded, 2 failed, 0 skipped ========== ========== Rebuild started at 10:19 AM and took 29.760 seconds ========== ```
Youssef1313 commented 1 year ago

To me it looks like these errors are unrelated to the use of file-scoped vs block-scoped namespaces.

So is this issue about two different issues?

For the file-scoped part, I guess Roslyn is supposed to respect that when creating new files. I would suggest first reporting to dotnet/roslyn

The implementation in Roslyn was done in https://github.com/dotnet/roslyn/pull/55504.

elibroftw commented 1 year ago

The .editorconfig change had no impact to how the blankpage looks like. And now I find that the compile errors are due to the use of the UWP page template instead of the other (why is the UWP before the SDK one then?). Still annoying having to change the block-scoped namespace to file-scoped namespace every time I create a new page.

Youssef1313 commented 1 year ago

The .editorconfig change had no impact to how the blankpage looks like.

That looks like a Roslyn bug. So I recommend first opening an issue there. As mentioned, the functionality was supposed to be implemented in https://github.com/dotnet/roslyn/pull/55504 (cc @davidwengier)

Youssef1313 commented 1 year ago

For the ordering of the item templates, I'm not sure. @dansiegel is this something we control?