Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid sourceName transformation in SLN files #1920

Closed
TimLariviere opened this issue Jun 7, 2019 · 2 comments
Closed

Invalid sourceName transformation in SLN files #1920

TimLariviere opened this issue Jun 7, 2019 · 2 comments
Labels
size:2.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Milestone

Comments

@TimLariviere
Copy link

TimLariviere commented Jun 7, 2019

If a template contains both a project and a solution file, when running dotnet new -n "My Project" with spaces in the name, the solution file has the wrong path to the project file.

image

Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Project_name", "Project_name\Project_name.fsproj", "{1FCD22FE-82F2-48DD-9AA8-B75283EA36C9}"
EndProject

This issue is similar to #1168, which is closed but there is no satisfying solution found.

Expected

The SLN file should follow the same transformation than the folders/files, since it's where all paths are set.

Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Project Name", "Project Name\Project Name.fsproj", "{1FCD22FE-82F2-48DD-9AA8-B75283EA36C9}"
EndProject

Repro

  1. Create a template with a simple source name (e.g. NewApp) and a solution file and a project file
  2. Run dotnet new my-template -n "Project Name"
  3. Notice the folders and files contain are named Project Name
  4. Open the solution file, notice the path to the project was changed to Project_name

Quick repro:

dotnet new -i Fabulous.Templates
dotnet new fabulous-app -n "Project Name" --Android=false --iOS=false

Template.json for reference:
https://github.com/fsprojects/Fabulous/blob/244f61aa1ea7f5be00b2a165f6077a0f068e031a/templates/content/blank/.template.config/template.json#L17

@TroyWalshProf
Copy link

You also see this issue when the working directory has a space or dash.

So if I am in "C:\Users\TroyW\Desktop\Sample\With Space" and run:

dotnet new fabulous-app --Android=false --iOS=false

The new sln file will now have this:
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "With_Space", "With_Space\With_Space.fsproj", "{C2EF5A38-20E3-4B7D-BA17-6AE9A217B390}" EndProject

@vlada-shubina
Copy link
Member

This is known issue with using not safe sourceName. https://github.com/dotnet/templating/wiki/Naming-and-default-value-forms

sourceName used above is "sourceName": "NewApp".

Template engine applies 5 forms to the source name:

  • identity - no transformation
  • safe namespace
string workingValue = Regex.Replace(value, @"(^\s+|\s+$)", "");
workingValue = Regex.Replace(workingValue, @"(((?<=\.)|^)((?=\d)|\.)|[^\w\.])|(\.$)", "_");
  • safe class name
string workingValue = Regex.Replace(value, @"(^\s+|\s+$)", "");
workingValue = Regex.Replace(workingValue, @"(((?<=\.)|^)(?=\d)|\W)", "_");
  • lower safe namespace and lower safe class name (same as above + ToLowerInvariant)

The source name you chose in template.json should provide different results for the form above, similar to the name mentioned in https://github.com/dotnet/templating/wiki/Naming-and-default-value-forms:

Transform Input Output
Identity Template.1 Template.1
Namespace Template.1 Template._1
Class Name Template.1 Template__1
Lowercase Namespace Template.1 template._1
Lowercase Class Name Template.1 template__1

When sourceName is used in namespaces and class names, corresponding form should be used instead.
If the sourceName chosen is not safe, i.e. forms transformation results in same result, it's not guaranteed that correct form will be used when template engine replaces the values. This happened for the issue above:

  • NewApp is same for identity, namespace, and class name forms
  • user entered Project Name, which results in Project Name, Project Name, Project_Name respectively
  • template engine picked up one of latter 2 for all replacements: while it is correct for namespace, it is not correct for replacements made in solution files, where Project Name should have been used.

This should be solved by picking up different sourceName in template definition (for example NewApp.1) and use correct forms where needed. In sln identity NewApp.1 form should be used for original file name entered as -n option.

I'm closing this issue now, please don't hesitate to reach us out in case of further questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:2.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

5 participants