Skip to content

Commit 0c3b294

Browse files
authored
Use TargetAlias in AssetsFileDependencies snapshot (#6843)
1 parent e8da0a8 commit 0c3b294

1 file changed

Lines changed: 2 additions & 30 deletions

File tree

src/NuGet.Clients/NuGet.VisualStudio.Implementation/SolutionExplorer/Models/AssetsFileDependenciesSnapshot.cs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ private AssetsFileDependenciesSnapshot(LockFile? lockFile, AssetsFileDependencie
9696
continue;
9797
}
9898

99-
string targetAlias = GetTargetAlias(lockFileTarget.Name);
99+
string targetAlias = lockFileTarget.TargetAlias;
100100

101101
previous.DataByTarget.TryGetValue(targetAlias, out AssetsFileTarget? previousTarget);
102102

103-
ImmutableArray<AssetsFileLogMessage> logMessages = ParseLogMessages(lockFile, previousTarget, lockFileTarget.Name);
103+
ImmutableArray<AssetsFileLogMessage> logMessages = ParseLogMessages(lockFile, previousTarget, targetAlias);
104104

105105
dataByTarget.Add(
106106
targetAlias,
@@ -114,34 +114,6 @@ private AssetsFileDependenciesSnapshot(LockFile? lockFile, AssetsFileDependencie
114114
DataByTarget = dataByTarget.ToImmutable();
115115
return;
116116

117-
string GetTargetAlias(string lockFileTargetName)
118-
{
119-
// In some places, the target alias specified in the project file (e.g. "net472") will not
120-
// match the target name used throughout the lock file (e.g. ".NETFramework,Version=v4.7.2").
121-
// The dependencies tree only uses the target alias (what's in the project file) so we need
122-
// to map back to that. See https://github.com/dotnet/project-system/issues/6832.
123-
124-
if (lockFile.PackageSpec.TargetFrameworks.Any(t => t.TargetAlias == lockFileTargetName))
125-
{
126-
// The target name used in the assets file matches the target alias in the project file.
127-
return lockFileTargetName;
128-
}
129-
130-
// The target name used in the assets file does NOT match any target alias in the project.
131-
// Attempt to find the name used in the project.
132-
foreach (TargetFrameworkInformation targetInfo in lockFile.PackageSpec.TargetFrameworks)
133-
{
134-
if (targetInfo.FrameworkName.DotNetFrameworkName == lockFileTargetName)
135-
{
136-
// We found a match, so return the alias.
137-
return targetInfo.TargetAlias;
138-
}
139-
}
140-
141-
// No match was found. Not ideal. Nothing to do but return the original value.
142-
return lockFileTargetName;
143-
}
144-
145117
static ImmutableArray<AssetsFileLogMessage> ParseLogMessages(LockFile lockFile, AssetsFileTarget? previousTarget, string target)
146118
{
147119
if (lockFile.LogMessages.Count == 0)

0 commit comments

Comments
 (0)