AvaloniaUI / avalonia-dotnet-templates

Avalonia Templates for `dotnet new`
MIT License
514 stars 89 forks source link

Creating new items in Visual Studio doesn't replace invalid characters in namespace #244

Open joe7057 opened 9 months ago

joe7057 commented 9 months ago

Describe the bug

Normally when creating a new file in Visual Studio, if the project name has an invalid character such as a dash ("-"), when a new file is generated, the namespace will use a substituted valid character, such as an underscore ("_"). The Avalonia item types (Class, Window, etc.) do not do this, resulting in un-compliable code.

To Reproduce

Steps to reproduce the behavior:

  1. Create a new Avalonia project in Visual Studio and choose a project name that includes the character "-".
  2. Build the project. It will build properly.
  3. In solution explorer, right-click on a folder and choose "Add" -> "New Item". Add a class, Avalonia Window, Avalonia UserControl, or other Avalonia item.
  4. Check the namespace that is auto-defined in the associated .cs file. It will contain the "-", which is not an allowed character in the namespace. The code will not compile.

Expected behavior

The "-" should be removed or substituted with a valid character. Microsoft uses "_".

Screenshots

image image

Environment

hez2010 commented 9 months ago

I believe this should be reported to Roslyn repo. There's nothing we can do on the Avalonia side.