diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs index 3aad5d0b00d..ae1b0dc8ee0 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs @@ -22,7 +22,7 @@ namespace Test #nullable disable [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))] #nullable restore - public partial class _Imports : System.Object + public partial class _Imports : object #nullable disable { #pragma warning disable 219 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.ir.txt index 12f894ae58b..9dc9919ee8b 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.ir.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.ir.txt @@ -9,7 +9,7 @@ UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection CSharpCode - IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))] - ClassDeclaration - - public partial - _Imports - System.Object - + ClassDeclaration - - public partial - _Imports - object - DesignTimeDirective - DirectiveToken - (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) - MainLayout CSharpCode - diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt index b972467f2e0..ef86d7aee3c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentDesignTimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt @@ -10,11 +10,11 @@ Generated Location: (460:17,0 [23] ) Source Location: (56:3,8 [10] x:\dir\subdir\Test\_Imports.razor) |MainLayout| -Generated Location: (923:32,0 [10] ) +Generated Location: (916:32,0 [10] ) |MainLayout| Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) |Foo| -Generated Location: (1356:49,6 [3] ) +Generated Location: (1349:49,6 [3] ) |Foo| diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs index 38ea2ed985e..463a195dab3 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.codegen.cs @@ -24,7 +24,7 @@ namespace Test ; [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))] #nullable restore - public partial class _Imports : System.Object + public partial class _Imports : object #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.ir.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.ir.txt index 1020e1849b9..55f2c9c549c 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.ir.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.ir.txt @@ -9,7 +9,7 @@ UsingDirective - (21:1,1 [23] x:\dir\subdir\Test\_Imports.razor) - System.Reflection CSharpCode - IntermediateToken - - CSharp - [global::Microsoft.AspNetCore.Components.LayoutAttribute(typeof(MainLayout))] - ClassDeclaration - - public partial - _Imports - System.Object - + ClassDeclaration - - public partial - _Imports - object - MethodDeclaration - - protected - void - Execute CSharpExpression - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) LazyIntermediateToken - (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) - CSharp - Foo diff --git a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt index 348da246480..f82b0533170 100644 --- a/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt +++ b/src/Compiler/Microsoft.AspNetCore.Razor.Language/test/TestFiles/IntegrationTests/ComponentRuntimeCodeGenerationTest/ComponentImports/_Imports.mappings.txt @@ -10,6 +10,6 @@ Generated Location: (488:18,0 [23] ) Source Location: (69:4,1 [3] x:\dir\subdir\Test\_Imports.razor) |Foo| -Generated Location: (952:35,0 [3] ) +Generated Location: (945:35,0 [3] ) |Foo| diff --git a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs index 745dfe64907..b18ea044d1f 100644 --- a/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs +++ b/src/Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src/Language/Components/ComponentDocumentClassifierPass.cs @@ -99,7 +99,7 @@ protected override void OnDocumentStructureCreated( { // We don't want component imports to be considered as real component. // But we still want to generate code for it so we can get diagnostics. - @class.BaseType = IntermediateToken.CreateCSharpToken(typeof(object).FullName); + @class.BaseType = IntermediateToken.CreateCSharpToken("object"); method.ReturnType = "void"; method.MethodName = "Execute"; diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs index c92e78515fe..1eb307d8484 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/RazorSourceGeneratorComponentTests.cs @@ -76,6 +76,28 @@ @using System.Net.Http result.VerifyOutputsMatchBaseline(); } + [Fact] + public async Task ImportsRazor_SystemInNamespace() + { + // Arrange + var project = CreateTestProject(new() + { + ["System/_Imports.razor"] = """ + @using global::System.Net.Http + """, + }); + var compilation = await project.GetCompilationAsync(); + var driver = await GetDriverAsync(project); + + // Act + var result = RunGenerator(compilation!, ref driver); + + // Assert + result.Diagnostics.Verify(); + Assert.Single(result.GeneratedSources); + result.VerifyOutputsMatchBaseline(); + } + [Fact, WorkItem("https://github.com/dotnet/razor/issues/8718")] public async Task PartialClass() { diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor/Folder1__Imports_razor.g.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor/Folder1__Imports_razor.g.cs index a59cfb7da78..3a32131235b 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor/Folder1__Imports_razor.g.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor/Folder1__Imports_razor.g.cs @@ -18,7 +18,7 @@ namespace MyApp.Folder1 #nullable disable ; #nullable restore - public partial class _Imports : System.Object + public partial class _Imports : object #nullable disable { #pragma warning disable 1998 diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_SystemInNamespace/System__Imports_razor.g.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_SystemInNamespace/System__Imports_razor.g.cs new file mode 100644 index 00000000000..83a9570411e --- /dev/null +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_SystemInNamespace/System__Imports_razor.g.cs @@ -0,0 +1,31 @@ +#pragma checksum "System/_Imports.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "53b28fda6534c79c7b9a4da6dcc903c4b51cfab9" +// +#pragma warning disable 1591 +namespace MyApp.System +{ + #line default + using global::System; + using global::System.Collections.Generic; + using global::System.Linq; + using global::System.Threading.Tasks; + using global::Microsoft.AspNetCore.Components; +#nullable restore +#line (1,2)-(1,31) "System/_Imports.razor" +using global::System.Net.Http + +#line default +#line hidden +#nullable disable + ; + #nullable restore + public partial class _Imports : object + #nullable disable + { + #pragma warning disable 1998 + protected void Execute() + { + } + #pragma warning restore 1998 + } +} +#pragma warning restore 1591 diff --git a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_WithMarkup/_Imports_razor.g.cs b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_WithMarkup/_Imports_razor.g.cs index b5239126eee..008aee425ac 100644 --- a/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_WithMarkup/_Imports_razor.g.cs +++ b/src/Compiler/test/Microsoft.NET.Sdk.Razor.SourceGenerators.Tests/TestFiles/RazorSourceGeneratorComponentTests/ImportsRazor_WithMarkup/_Imports_razor.g.cs @@ -18,7 +18,7 @@ namespace MyApp #nullable disable ; #nullable restore - public partial class _Imports : System.Object + public partial class _Imports : object #nullable disable { #pragma warning disable 1998