Merge pull request #2363 from dotnet/troy/2344
Stop adding default desktop assembly reference repeatedly.
This commit is contained in:
commit
3d157d0ec8
8 changed files with 105 additions and 18 deletions
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"dependencies": {
|
||||
},
|
||||
"frameworks": {
|
||||
"net45": {
|
||||
"frameworkAssemblies": {
|
||||
"mscorlib": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
"NETStandard.Library": "1.5.0-rc2-24008"
|
||||
}
|
||||
},
|
||||
"dnx451": {
|
||||
"net451": {
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.0.1-rc2-24008"
|
||||
}
|
||||
|
|
16
TestAssets/TestProjects/TestMscorlibReference/project.json
Normal file
16
TestAssets/TestProjects/TestMscorlibReference/project.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-24008"
|
||||
}
|
||||
},
|
||||
"net451": {
|
||||
"frameworkAssemblies": {
|
||||
"mscorlib": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
TestAssets/TestProjects/TestSystemCoreReference/project.json
Normal file
16
TestAssets/TestProjects/TestSystemCoreReference/project.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-24008"
|
||||
}
|
||||
},
|
||||
"net451": {
|
||||
"frameworkAssemblies": {
|
||||
"System": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
TestAssets/TestProjects/TestSystemReference/project.json
Normal file
16
TestAssets/TestProjects/TestSystemReference/project.json
Normal file
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandardapp1.5": {
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.5.0-rc2-24008"
|
||||
}
|
||||
},
|
||||
"net451": {
|
||||
"frameworkAssemblies": {
|
||||
"System.Core": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -44,31 +44,26 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
|||
{
|
||||
// This never returns null
|
||||
var targetFrameworkInfo = project.GetTargetFramework(targetFramework);
|
||||
var dependencies = new List<LibraryRange>(targetFrameworkInfo.Dependencies);
|
||||
var dependencies = new List<LibraryRange>(targetFrameworkInfo.Dependencies);
|
||||
|
||||
// Add all of the project's dependencies
|
||||
dependencies.AddRange(project.Dependencies);
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (targetLibrary != null)
|
||||
{
|
||||
// The lock file entry might have a filtered set of dependencies
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,15 +42,25 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
|||
Assert.Empty(p2.RuntimeAssemblies);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SingleMicrosoftCSharpReference()
|
||||
[Theory]
|
||||
[InlineDataAttribute("TestMscorlibReference", true)]
|
||||
[InlineDataAttribute("TestMscorlibReference", false)]
|
||||
[InlineDataAttribute("TestMicrosoftCSharpReference", true)]
|
||||
[InlineDataAttribute("TestMicrosoftCSharpReference", false)]
|
||||
[InlineDataAttribute("TestSystemReference", true)]
|
||||
[InlineDataAttribute("TestSystemReference", false)]
|
||||
[InlineDataAttribute("TestSystemCoreReference", true)]
|
||||
[InlineDataAttribute("TestSystemCoreReference", false)]
|
||||
public void TestDuplicateDefaultDesktopReferences(string sampleName, bool withLockFile)
|
||||
{
|
||||
// https://github.com/dotnet/cli/issues/1602
|
||||
var instance = TestAssetsManager.CreateTestInstance("TestMicrosoftCSharpReference")
|
||||
.WithLockFiles();
|
||||
var instance = TestAssetsManager.CreateTestInstance(sampleName);
|
||||
if (withLockFile)
|
||||
{
|
||||
instance = instance.WithLockFiles();
|
||||
}
|
||||
|
||||
var context = new ProjectContextBuilder().WithProjectDirectory(instance.TestRoot)
|
||||
.WithTargetFramework("dnx451")
|
||||
.WithTargetFramework("net451")
|
||||
.Build();
|
||||
|
||||
Assert.Equal(4, context.RootProject.Dependencies.Count());
|
||||
|
|
|
@ -595,6 +595,21 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
afterDependencies.RetrieveDependency("ClassLibrary3");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestMscorlibLibraryDuplication()
|
||||
{
|
||||
var projectPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "MscorlibLibraryDuplication");
|
||||
|
||||
using (var server = new DthTestServer(_loggerFactory))
|
||||
using (var client = new DthTestClient(server, _loggerFactory))
|
||||
{
|
||||
client.Initialize(projectPath);
|
||||
|
||||
var messages = client.DrainAllMessages();
|
||||
messages.AssertDoesNotContain(MessageTypes.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static string NormalizePathString(string original)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue