diff --git a/TestAssets/TestProjects/DependencyContextValidator/TestAppFullClr/project.json b/TestAssets/TestProjects/DependencyContextValidator/TestAppFullClr/project.json index e97a70f55..4962b2526 100644 --- a/TestAssets/TestProjects/DependencyContextValidator/TestAppFullClr/project.json +++ b/TestAssets/TestProjects/DependencyContextValidator/TestAppFullClr/project.json @@ -5,9 +5,13 @@ "preserveCompilationContext": true }, "dependencies": { - "DependencyContextValidator": "1.0.0-*" + "DependencyContextValidator": "1.0.0-*", + "System.Diagnostics.Process": { + "version": "4.1.0-*", + "type": "build" + } }, "frameworks": { - "net451": {} + "net46": {} } } \ No newline at end of file diff --git a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs index 0b80bfef5..c18795c51 100644 --- a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs +++ b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs @@ -15,6 +15,7 @@ using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.Extensions.DependencyModel; using NuGet.Frameworks; +using Microsoft.DotNet.ProjectModel.Graph; namespace Microsoft.DotNet.Tools.Compiler { @@ -125,9 +126,15 @@ namespace Microsoft.DotNet.Tools.Compiler if (compilationOptions.PreserveCompilationContext == true) { var allExports = exporter.GetAllExports().ToList(); + var exportsLookup = allExports.ToDictionary(e => e.Library.Identity.Name); + var buildExclusionList = context.GetTypeBuildExclusionList(exportsLookup); + var filteredExports = allExports + .Where(e => e.Library.Identity.Type.Equals(LibraryType.ReferenceAssembly) || + !buildExclusionList.Contains(e.Library.Identity.Name)); + var dependencyContext = new DependencyContextBuilder().Build(compilationOptions, - allExports, - allExports, + filteredExports, + filteredExports, false, // For now, just assume non-portable mode in the legacy deps file (this is going away soon anyway) context.TargetFramework, context.RuntimeIdentifier ?? string.Empty);