Avoid add default desktop references repeatedly

This commit is contained in:
Troy Dai 2016-04-07 21:32:25 -07:00
parent 6a678a0d05
commit 031862dc05

View file

@ -51,20 +51,15 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
if (targetFramework != null && targetFramework.IsDesktop())
{
dependencies.Add(new LibraryRange("mscorlib", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
dependencies.Add(new LibraryRange("System", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
AddIfMissing(dependencies, "mscorlib");
AddIfMissing(dependencies, "System");
if (targetFramework.Version >= new Version(3, 5))
{
dependencies.Add(new LibraryRange("System.Core", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
AddIfMissing(dependencies, "System.Core");
if (targetFramework.Version >= new Version(4, 0))
{
if (!dependencies.Any(dep => string.Equals(dep.Name, "Microsoft.CSharp", StringComparison.OrdinalIgnoreCase)))
{
dependencies.Add(new LibraryRange("Microsoft.CSharp", LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
}
AddIfMissing(dependencies, "Microsoft.CSharp");
}
}
}
@ -89,5 +84,13 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
targetFrameworkInfo,
!unresolved);
}
private static void AddIfMissing(List<LibraryRange> dependencies, string dependencyName)
{
if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase)))
{
dependencies.Add(new LibraryRange(dependencyName, LibraryType.ReferenceAssembly, LibraryDependencyType.Build));
}
}
}
}