diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs index f9dddb7d8719..a0d1bfcca908 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs @@ -27,6 +27,9 @@ public class GenerateRuntimeConfigurationFiles : TaskBase [Required] public string TargetFramework { get; set; } + [Required] + public string TargetFrameworkMoniker { get; set; } + [Required] public string RuntimeConfigPath { get; set; } @@ -56,7 +59,7 @@ protected override void ExecuteCore() { LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); ProjectContext projectContext = lockFile.CreateProjectContext( - NuGetUtils.ParseFrameworkName(TargetFramework), + NuGetUtils.ParseFrameworkName(TargetFrameworkMoniker), RuntimeIdentifier, PlatformLibraryName); @@ -99,6 +102,7 @@ private void AddFramework(RuntimeOptions runtimeOptions, ProjectContext projectC } runtimeOptions.Framework = framework; + runtimeOptions.tfm = TargetFramework; } } } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs b/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs index f1cb931145c8..b0bf3d26254f 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/LockFileExtensions.cs @@ -16,7 +16,8 @@ public static ProjectContext CreateProjectContext( this LockFile lockFile, NuGetFramework framework, string runtime, - string platformLibraryName) + string platformLibraryName, + LockFile filterlockFile = null) { if (lockFile == null) { @@ -28,6 +29,12 @@ public static ProjectContext CreateProjectContext( } LockFileTarget lockFileTarget = lockFile.GetTarget(framework, runtime); + LockFileTarget filterlockFileTarget = null; + + if (filterlockFile != null) + { + filterlockFileTarget = filterlockFile.GetTarget(framework, runtime); + } if (lockFileTarget == null) { @@ -39,7 +46,7 @@ public static ProjectContext CreateProjectContext( throw new BuildErrorException(Strings.AssetsFileMissingTarget, lockFile.Path, targetMoniker, framework.GetShortFolderName(), runtime); } - return new ProjectContext(lockFile, lockFileTarget, platformLibraryName); + return new ProjectContext(lockFile, lockFileTarget, platformLibraryName, filterlockFileTarget); } public static LockFileTargetLibrary GetLibrary(this LockFileTarget lockFileTarget, string libraryName) @@ -76,6 +83,7 @@ public static Dictionary GetProjectFileDependencies(this LockFil return projectDeps; } + public static HashSet GetPlatformExclusionList( this LockFileTarget lockFileTarget, diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs index 2c4c4cb67954..07a53706d5a0 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ProjectContext.cs @@ -12,6 +12,7 @@ namespace Microsoft.NET.Build.Tasks public class ProjectContext { private readonly LockFile _lockFile; + private readonly LockFileTarget _filterlockFileTarget; private readonly LockFileTarget _lockFileTarget; private readonly string _platformLibraryName; @@ -21,9 +22,10 @@ public class ProjectContext public LockFile LockFile => _lockFile; public LockFileTarget LockFileTarget => _lockFileTarget; - public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget, string platformLibraryName) + public ProjectContext(LockFile lockFile, LockFileTarget lockFileTarget, string platformLibraryName, LockFileTarget filterlockFileTarget = null) { _lockFile = lockFile; + _filterlockFileTarget = filterlockFileTarget; _lockFileTarget = lockFileTarget; _platformLibraryName = platformLibraryName; @@ -54,6 +56,14 @@ public IEnumerable GetRuntimeLibraries(IEnumerable filterLibraries = _filterlockFileTarget.Libraries; + Dictionary filterLookup = filterLibraries.ToDictionary(e => e.Name, StringComparer.OrdinalIgnoreCase); + + allExclusionList.UnionWith(GetIntersection(filterLookup, libraryLookup)); + } + return runtimeLibraries.Filter(allExclusionList).ToArray(); } @@ -171,5 +181,35 @@ public HashSet GetPrivateAssetsExclusionList( return privateAssetsToExclude; } + private static HashSet GetIntersection( + IDictionary collection1, + IDictionary collection2) + { + var exclusionList = new HashSet(); + var iterated = collection1; + var lookup = collection2; + + if (collection1.Count > collection2.Count) + { + iterated = collection2; + lookup = collection1; + } + foreach (var entry in iterated) + { + LockFileTargetLibrary library = lookup[entry.Key]; + + if (library != null) + { + LockFileTargetLibrary dependency = entry.Value; + + if (library.Version.Equals(dependency.Version)) + { + exclusionList.Add(entry.Key); + } + } + } + + return exclusionList; + } } } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePublishAssemblies.cs b/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePublishAssemblies.cs index 53fecf2ca557..cf986386db8e 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePublishAssemblies.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/ResolvePublishAssemblies.cs @@ -29,8 +29,11 @@ public class ResolvePublishAssemblies : TaskBase public string PlatformLibraryName { get; set; } public ITaskItem[] PrivateAssetsPackageReferences { get; set; } - + public bool PreserveCacheLayout { get; set; } + + public string FilterProjectAssetsFile { get; set; } + /// /// All the assemblies to publish. /// @@ -42,16 +45,25 @@ public ITaskItem[] AssembliesToPublish protected override void ExecuteCore() { - LockFile lockFile = new LockFileCache(BuildEngine4).GetLockFile(AssetsFilePath); + var lockFileCache = new LockFileCache(BuildEngine4); + LockFile lockFile = lockFileCache.GetLockFile(AssetsFilePath); IEnumerable privateAssetsPackageIds = PackageReferenceConverter.GetPackageIds(PrivateAssetsPackageReferences); IPackageResolver packageResolver = NuGetPackageResolver.CreateResolver(lockFile, ProjectPath); + LockFile filterLockFile = null; + if (!string.IsNullOrEmpty(FilterProjectAssetsFile)) + { + filterLockFile = lockFileCache.GetLockFile(FilterProjectAssetsFile); + + } ProjectContext projectContext = lockFile.CreateProjectContext( NuGetUtils.ParseFrameworkName(TargetFramework), RuntimeIdentifier, - PlatformLibraryName); + PlatformLibraryName, + filterLockFile + ); - IEnumerable resolvedAssemblies = + IEnumerable resolvedAssemblies = new PublishAssembliesResolver(packageResolver) .WithPrivateAssets(privateAssetsPackageIds) .WithPreserveCacheLayout(PreserveCacheLayout) diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/RuntimeOptions.cs b/src/Tasks/Microsoft.NET.Build.Tasks/RuntimeOptions.cs index 9f45fbe33708..78feed856add 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/RuntimeOptions.cs +++ b/src/Tasks/Microsoft.NET.Build.Tasks/RuntimeOptions.cs @@ -9,6 +9,8 @@ namespace Microsoft.NET.Build.Tasks { internal class RuntimeOptions { + public string tfm { get; set; } + public RuntimeConfigFramework Framework { get; set; } public List AdditionalProbingPaths { get; set; } diff --git a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets index f497ba10a4dc..e7a1539166e0 100644 --- a/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets +++ b/src/Tasks/Microsoft.NET.Build.Tasks/build/Microsoft.NET.Publish.targets @@ -227,10 +227,12 @@ Copyright (c) .NET Foundation. All rights reserved. + + + + + + $(MSBuildProjectExtensionsPath)\filterprofile + $(FilterProjFileDir)\project.assets.json + + + + + +