dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.59k stars 1.03k forks source link

Cannot create a `blazorwasm` or `blazor` template project with name including emoji #41667

Open radical opened 2 weeks ago

radical commented 2 weeks ago

Is there an existing issue for this?

Describe the bug

Project created with - dotnet new blazorwasm -o "blazorwasm_πŸ˜€", fails to build with:

 $ dotnet build -bl
Restore complete (15.9s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  blazorwasm_πŸ˜€ failed with errors (1.8s)
    /private/tmp/bl/blazorwasm_πŸ˜€/Program.cs(3,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(9,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]
    /private/tmp/bl/blazorwasm_πŸ˜€/_Imports.razor(10,7): error CS0246: The type or namespace name 'blazorwasm__' could not be found (are you missing a using directive or an assembly reference?) [/private/tmp/bl/blazorwasm_πŸ˜€/blazorwasm_πŸ˜€.csproj]

Build failed with errors in 17.9s

This was with .net sdk 9.0.100-preview.3.24157.9. It is also reproducible with 8.0.200.

Expected Behavior

No response

Steps To Reproduce

  1. dotnet new blazorwasm -o "blazorwasm_πŸ˜€"
  2. cd "blazorwasm_πŸ˜€"
  3. dotnet build

Exceptions (if any)

No response

.NET Version

No response

Anything else?

.log appended to the name to satisfy github. msbuild.binlog.log

javiercn commented 2 weeks ago

@radical does this not happen with other templates?

radical commented 2 weeks ago

@radical does this not happen with other templates?

It happens with blazor template too. But it works fine with the console template. This sounds blazor specific as it is generating _Imports.razor:

...
@using blazor__
@using blazor__.Components

And the csproj has:

blazor_πŸ˜€.csproj
    <RootNamespace>blazor_πŸ˜€</RootNamespace>
javiercn commented 2 weeks ago

@radical thanks for the additional details.

I think this might be a template bug? We are using the right template expression for the safe namespace bit https://github.com/dotnet/aspnetcore/blob/main/src/ProjectTemplates/Web.ProjectTemplates/BlazorWeb-CSharp.csproj.in#L9

radical commented 2 weeks ago

Moving this to the sdk then.

MackinnonBuck commented 1 week ago

@baronfel Do you know who can help out with this on the template engine side? We think we're doing everything necessary to generate safe names.

baronfel commented 1 week ago

This is fascinating. When I create this template with -v diag here's the output I see for the name value forms:

[2024-06-20 11:51:05.482] [Debug] [Template Engine] => [Execute] => [Template content generation]: [JoinMacro]: Variable 'name{-VALUE-FORMS-}identity' was assigned to value 'blazorwasm_πŸ˜€'.
[2024-06-20 11:51:05.482] [Debug] [Template Engine] => [Execute] => [Template content generation]: [JoinMacro]: Variable 'name{-VALUE-FORMS-}safe_name' was assigned to value 'blazorwasm___'.
[2024-06-20 11:51:05.482] [Debug] [Template Engine] => [Execute] => [Template content generation]: [JoinMacro]: Variable 'name{-VALUE-FORMS-}lower_safe_name' was assigned to value 'blazorwasm___'.
[2024-06-20 11:51:05.482] [Debug] [Template Engine] => [Execute] => [Template content generation]: [JoinMacro]: Variable 'name{-VALUE-FORMS-}safe_namespace' was assigned to value 'blazorwasm__'.
[2024-06-20 11:51:05.482] [Debug] [Template Engine] => [Execute] => [Template content generation]: [JoinMacro]: Variable 'name{-VALUE-FORMS-}lower_safe_namespace' was assigned to value 'blazorwasm__'.

To me, I look at this and think the same as you @MackinnonBuck - using the name{-VALUE-FORMS-}safe_namespace should get the useable name set on the RootNamespace. But that doesn't seem to be happening. So I'd say this is a bug in the engine, but we'd need to get a deeper investigation for full details. I'll see if we can find some more details.