diff --git a/TestAssets/TestProjects/TestMicrosoftCSharpReferenceMissingFramework/project.json b/TestAssets/TestProjects/TestMicrosoftCSharpReferenceMissingFramework/project.json index b90b25407..353b6b488 100644 --- a/TestAssets/TestProjects/TestMicrosoftCSharpReferenceMissingFramework/project.json +++ b/TestAssets/TestProjects/TestMicrosoftCSharpReferenceMissingFramework/project.json @@ -8,6 +8,11 @@ "Microsoft.NETCore.App": "1.0.0-rc2-*" } }, + "netcore50": { + "dependencies": { + "System.Private.Uri": "4.0.1-rc2-24018" + } + }, "net99": { "dependencies": { "Microsoft.CSharp": "4.0.1-rc2-24018" diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index dbd906f91..0c22afca3 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -380,7 +380,7 @@ namespace Microsoft.DotNet.ProjectModel if (package != null && package.Resolved && package.HasCompileTimePlaceholder && - !TargetFramework.IsPackageBased) + !TargetFramework.IsPackageBased()) { var newKey = new LibraryKey(library.Identity.Name, LibraryType.ReferenceAssembly); var dependency = new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly); diff --git a/src/Microsoft.DotNet.ProjectModel/Utilities/FrameworksExtensions.cs b/src/Microsoft.DotNet.ProjectModel/Utilities/FrameworksExtensions.cs index 6cbab643c..11f85b6b3 100644 --- a/src/Microsoft.DotNet.ProjectModel/Utilities/FrameworksExtensions.cs +++ b/src/Microsoft.DotNet.ProjectModel/Utilities/FrameworksExtensions.cs @@ -1,7 +1,7 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System.Linq; +using System; using System.Runtime.Versioning; namespace NuGet.Frameworks @@ -56,5 +56,12 @@ namespace NuGet.Frameworks } return name + "-" + frameworkName.Profile; } + + public static bool IsPackageBased(this NuGetFramework self) + { + return self.IsPackageBased || + (self.Framework == FrameworkConstants.FrameworkIdentifiers.NetCore && + self.Version >= new Version(5, 0, 0, 0)); + } } } diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs index 756ac7b6c..406a617b1 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/PackageDependencyProviderTests.cs @@ -76,7 +76,22 @@ namespace Microsoft.DotNet.ProjectModel.Tests .WithTargetFramework("net99") .Build(); + // Will fail with dupes if any context.LibraryManager.GetLibraries().ToDictionary(l => l.Identity.Name); } + + [Fact] + public void NetCore50ShouldNotResolveFrameworkAssemblies() + { + var instance = TestAssetsManager.CreateTestInstance("TestMicrosoftCSharpReferenceMissingFramework") + .WithLockFiles(); + + var context = new ProjectContextBuilder().WithProjectDirectory(instance.TestRoot) + .WithTargetFramework("netcore50") + .Build(); + + var diagnostics = context.LibraryManager.GetAllDiagnostics(); + Assert.False(diagnostics.Any(d => d.ErrorCode == ErrorCodes.DOTNET1011)); + } } }