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.21k stars 9.95k forks source link

Code generation problem if project name contains "-" (dash, minus) #40816

Open buraksarica opened 2 years ago

buraksarica commented 2 years ago

Describe the bug

dotnet new mvc command produces faulty style reference if project name contains - character.

To Reproduce

Using cli version 6.0.2.

mkdir cloud-manager
cd cloud-manager
dotnet new mvc

Further technical details

The cli generated the project successfuly. But the _layout.cshtml file has a reference to "cloudmanager.styles.css" which needs to be "cloud-manager.styles.css". So until changing the to -, the site doesn't look properly due to a 404 error.

The generator seems falsely to use root namespace name instead of project output name.

dsplaisted commented 2 years ago

I transferred this to the templating repo. I'm not sure if this is an issue with the templating engine itself or with the templates.

vlada-shubina commented 2 years ago

Team, transferring issue to you. I checked it and it is indeed the case due to ambiguous source name.

I would recommend to change the source name to Company.WebApplication.1 to avoid ambiguous forms, see https://github.com/dotnet/templating/wiki/Naming-and-default-value-forms.

In the current setup the following forms are used: Transform Input Output
Identity Company.WebApplication1 Company.WebApplication1
Namespace Company.WebApplication1 Company.WebApplication1 (same as identity)
Class Name Company.WebApplication1 Company_WebApplication1
Lowercase Namespace Company.WebApplication1 company.webapplication1
Lowercase Class Name Company.WebApplication1 company_webapplication1
Adding period will make a difference Transform Input Output
Identity Company.WebApplication.1 Company.WebApplication.1
Namespace Company.WebApplication.1 Company.WebApplication._1
Class Name Company.WebApplication.1 Company_WebApplication_1
Lowercase Namespace Company.WebApplication.1 company.webapplication._1
Lowercase Class Name Company.WebApplication.1 company_webapplication_1
mkArtakMSFT commented 2 years ago

Thanks for contacting us, @buraksarica. @vlada-shubina what do we put here to make sure that it matches the project name?

ghost commented 2 years 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.

vlada-shubina commented 2 years ago

Thanks for contacting us, @buraksarica. @vlada-shubina what do we put here to make sure that it matches the project name?

My recommendation is to change sourceName in template.json to Company.WebApplication.1 here(https://github.com/dotnet/aspnetcore/blob/f902dd8e154b2d20555a294ce83d21ddffaee8c4/src/ProjectTemplates/Web.ProjectTemplates/content/RazorPagesWeb-CSharp/.template.config/template.json#L24). Then in template content:

@sayedihashimi just a heads up, this issue is a good candidate to be included in template validation, happened already couple of times.