dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.57k stars 10.05k forks source link

Creating an app named "App" breaks _Imports.razor #51805

Open tmat opened 2 years ago

tmat commented 2 years ago

Seems like the generator needs to disambiguate the App identifier.

D:\Temp\App>dotnet --version
7.0.100-preview.7.22377.5
D:\Temp\App>dotnet new blazorserver
The template "Blazor Server App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/7.0-third-party-notices for details.

Processing post-creation actions...
Restoring D:\Temp\App\App.csproj:
  Determining projects to restore...
  Restored D:\Temp\App\App.csproj (in 61 ms).
Restore succeeded.
D:\Temp\App>dotnet run
Building...
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\Pages\FetchData.razor(2,11): error CS0426: The type name 'Data' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(9,7): error CS0138: A 'using namespace' directive can only be applied to namespaces; 'App' is a type not a namespace. Consider a 'using static' directive instead [D:\Temp\App\App.csproj]
D:\Temp\App\_Imports.razor(10,11): error CS0426: The type name 'Shared' does not exist in the type 'App' [D:\Temp\App\App.csproj]
D:\Temp\App\Microsoft.NET.Sdk.Razor.SourceGenerators\Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator\Pages_FetchData_razor.g.cs(206,75): error CS0246: The type or namespace name 'WeatherForecastService' could not be found (are you missing a u
sing directive or an assembly reference?) [D:\Temp\App\App.csproj]
D:\Temp\App\Pages\FetchData.razor(41,13): error CS0246: The type or namespace name 'WeatherForecast' could not be found (are you missing a using directive or an assembly reference?) [D:\Temp\App\App.csproj]

The build failed. Fix the build errors and run again.
jjonescz commented 1 year ago

I don't think this is a bug in the compiler, it behaves as expected. The problem is that the template generates App.razor and also _Imports.razor which contains @using App. That simply cannot work. The template could either emit an error if the user wants to generate a project named App or use a different name for App.razor in that case.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.