Skip to content

Fix case-sensitive path comparison in GlobalSettingsTemplatePackageProvider.EnsureInstallPrerequisites#55105

Open
Happypig375 wants to merge 2 commits into
dotnet:mainfrom
Happypig375:fix-case-sensitive-template-identifier
Open

Fix case-sensitive path comparison in GlobalSettingsTemplatePackageProvider.EnsureInstallPrerequisites#55105
Happypig375 wants to merge 2 commits into
dotnet:mainfrom
Happypig375:fix-case-sensitive-template-identifier

Conversation

@Happypig375

Copy link
Copy Markdown
Member

Description

The EnsureInstallPrerequisites method in GlobalSettingsTemplatePackageProvider uses ordinal (case-sensitive) comparison (s.Identifier == identifier) to detect if a managed template package is already installed. On Windows, file paths can have different drive letter casing (e.g., c:\path vs C:\path), causing the check to miss existing packages.

Repro

# First install with one casing
dotnet new install "c:\templates\my-template"

# Re-install with different casing + --force
dotnet new install "C:\templates\my-template" --force

The second command succeeds but doesn't remove the old entry (because "c:\..." != "C:\..." with ordinal comparison). Both packages survive, and the template cache reports overlapping identity conflicts:

The following templates use the same identity '...'

Fix

Changed s.Identifier == identifier to use string.Equals(s.Identifier, identifier, StringComparison.OrdinalIgnoreCase).

This matches the behavior of TemplatePackageCoordinator.ValidateInstallationRequestsAsync and TemplatePackageCoordinator.DetermineSourcesToUninstallAsync which already use case-insensitive comparison.

…emplate packages

The EnsureInstallPrerequisites method in GlobalSettingsTemplatePackageProvider
used ordinal (case-sensitive) comparison (s.Identifier == identifier) to check
if a managed template package is already installed. On Windows, file paths can
have different drive letter casing (e.g., 'c:\path' vs 'C:\path'), causing
the check to miss existing packages.

When --force re-installs a folder template with different path casing, the old
entry is not detected as a duplicate, so both survive. This leads to the
template cache reporting overlapping identity conflicts.

Fix by using StringComparison.OrdinalIgnoreCase to match the behavior of
ValidateInstallationRequestsAsync and DetermineSourcesToUninstallAsync
which already use case-insensitive comparison.
Copilot AI review requested due to automatic review settings July 1, 2026 18:23
@Happypig375 Happypig375 requested a review from a team as a code owner July 1, 2026 18:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes duplicate managed template-package entries caused by case-sensitive identifier comparison when reinstalling the same local template path with different casing (notably drive-letter casing on Windows).

Changes:

  • Switches the “already installed” check in GlobalSettingsTemplatePackageProvider.EnsureInstallPrerequisites to use StringComparison.OrdinalIgnoreCase for identifier comparison.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants