dotnet / dotnet/sdk

`dotnet new` duplicate template warning is ambiguous

Open
#54,177 0 comments 0 reactions 0 assignees View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

If you have multiple templates installed that duplicate identity for some reason, then the current warning message is ambiguous.

E.g.

```
Warning:
The following templates use the same identity 'SomeNamespace.ProjectTemplate':
• 'Project Template Name' from 'c:\code\ProjectTemplateA'
• 'Project Template Name' from 'd:\other\ProjectTemplateB'
The template from 'Project Template Name' will be used. To resolve this conflict, uninstall the conflicting template packages.
```

Here the final `"Project Template Name" will be used` message doesn't help differentiate which template was actually used as they both have the same name, we need the path to understand which template was actually used.

(We have this come up as we have a submodule handle templating, and so across various project usages from downstream projects they can both install the same templates from their different source locations. I know this warning is intended to tell us we should uninstall one, but we're generally specifying from within the folder structure of where the template should be, but it'd be good to verify that behavior.)

### To Reproduce

Looks like this section of code:

https://github.com/dotnet/sdk/blob/7bfcbfa069151ac1f7b602fd4cad874f99fb2c1d/src/TemplateEngine/Microsoft.TemplateEngine.Edge/Settings/TemplateCache.cs#L173-L199

If I'm reading the prior section which lists out the directories correctly, I think it could just be a matter of swapping out the last parameter of the last message with printing the directory path of the selected package over the template name:

```diff
logger.LogWarning(string.Format(
LocalizableStrings.TemplatePackageManager_Warning_DetectedTemplatesIdentityConflict,
identityToTemplates.Key,
templatesList.ToString().TrimEnd(Environment.NewLine.ToCharArray()),
- lastTemplate.Template.Name));
+ lastTemplate.TemplatePackage.DisplayName));
```

### Further technical details
details of dotnet --info


.NET SDK:
Version: 10.0.201
Commit: 4d3023de60
Workload version: 10.0.200-manifests.02194a9c
MSBuild version: 18.3.0-release-26153-122+4d3023de6

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.201\

.NET workloads installed:
[maccatalyst]
Installation Source: VS 18.4.11612.150, VS 17.14.36717.8
Manifest Version: 26.2.10217/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maccatalyst\26.2.10217\WorkloadManifest.json
Install Type: Msi

[ios]
Installation Source: VS 18.4.11612.150, VS 17.14.36717.8
Manifest Version: 26.2.10217/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.ios\26.2.10217\WorkloadManifest.json
Install Type: Msi

[android]
Installation Source: VS 18.4.11612.150, VS 17.14.36717.8
Manifest Version: 36.1.30/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.android\36.1.30\WorkloadManifest.json
Install Type: Msi

[maui-windows]
Installation Source: VS 18.4.11612.150, VS 17.14.36717.8
Manifest Version: 10.0.20/10.0.100
Manifest Path: C:\Program Files\dotnet\sdk-manifests\10.0.100\microsoft.net.sdk.maui\10.0.20\WorkloadManifest.json
Install Type: Msi

Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.7
Architecture: x64
Commit: b16286c228

.NET SDKs installed:
9.0.308 [C:\Program Files\dotnet\sdk]
10.0.107 [C:\Program Files\dotnet\sdk]
10.0.201 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.