Skip to content

Commit 90898c7

Browse files
committed
Include only PackageReferences included at runtime
1 parent b18400f commit 90898c7

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class GenerateDepsFile : TaskBase
6464

6565
public ITaskItem CompilerOptions { get; set; }
6666

67-
public ITaskItem[] ExcludeFromPublishPackageReferences { get; set; } = Array.Empty<ITaskItem>();
67+
public ITaskItem[] AllPackageReferences { get; set; } = Array.Empty<ITaskItem>();
6868

6969
public ITaskItem[] RuntimeStorePackages { get; set; }
7070

@@ -228,13 +228,21 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
228228
targetFramework: TargetFramework);
229229
}
230230

231+
Func<ITaskItem, bool> ShouldNotBeInDepsFile = taskItem =>
232+
{
233+
var excludedAssets = taskItem.GetMetadata("ExcludeAssets");
234+
var includedAssets = taskItem.GetMetadata("IncludeAssets");
235+
return excludedAssets?.Contains("runtime") == true || excludedAssets?.Contains("all") == true ||
236+
(!string.IsNullOrEmpty(includedAssets) && !includedAssets.Contains("runtime") && !includedAssets.Contains("all"));
237+
};
238+
231239
builder = builder
232240
.WithMainProjectInDepsFile(IncludeMainProject)
233241
.WithReferenceAssemblies(referenceAssemblyInfos)
234242
.WithDirectReferences(directReferences)
235243
.WithDependencyReferences(dependencyReferences)
236244
.WithReferenceProjectInfos(referenceProjects)
237-
.WithExcludeFromPublishAssets(PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences))
245+
.WithExcludeFromPublishAssets(PackageReferenceConverter.GetPackageIds(AllPackageReferences?.Where(ShouldNotBeInDepsFile)))
238246
.WithRuntimePackAssets(runtimePackAssets)
239247
.WithCompilationOptions(compilationOptions)
240248
.WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())

src/Tasks/Microsoft.NET.Build.Tasks/PackageReferenceConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace Microsoft.NET.Build.Tasks
77
{
88
internal static class PackageReferenceConverter
99
{
10-
public static IEnumerable<string> GetPackageIds(ITaskItem[] packageReferences)
10+
public static IEnumerable<string> GetPackageIds(IEnumerable<ITaskItem> packageReferences)
1111
{
1212
if (packageReferences == null)
1313
{

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,7 @@ Copyright (c) .NET Foundation. All rights reserved.
12361236
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
12371237
RuntimeFrameworks="@(RuntimeFramework)"
12381238
CompilerOptions="@(DependencyFileCompilerOptions)"
1239-
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
1239+
AllPackageReferences="@(PackageReference)"
12401240
RuntimeStorePackages="@(RuntimeStorePackages)"
12411241
CompileReferences="@(ResolvedCompileFileDefinitions)"
12421242
ResolvedNuGetFiles="@(_ResolvedNuGetFilesForPublish)"

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ Copyright (c) .NET Foundation. All rights reserved.
338338
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
339339
RuntimeFrameworks="@(RuntimeFramework)"
340340
CompilerOptions="@(DependencyFileCompilerOptions)"
341-
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
341+
AllPackageReferences="@(PackageReference)"
342342
CompileReferences="@(ResolvedCompileFileDefinitions)"
343343
ResolvedNuGetFiles="@(NativeCopyLocalItems);@(ResourceCopyLocalItems);@(RuntimeCopyLocalItems)"
344344
UserRuntimeAssemblies="@(UserRuntimeAssembly)"

0 commit comments

Comments
 (0)