Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include only PackageReferences included at runtime in deps.json #46218

Open
wants to merge 2 commits into
base: release/9.0.3xx
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class GenerateDepsFile : TaskBase

public ITaskItem CompilerOptions { get; set; }

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

public ITaskItem[] RuntimeStorePackages { get; set; }

Expand Down Expand Up @@ -228,13 +228,21 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
targetFramework: TargetFramework);
}

Func<ITaskItem, bool> ShouldNotBeInDepsFile = taskItem =>
{
var excludedAssets = taskItem.GetMetadata("ExcludeAssets");
var includedAssets = taskItem.GetMetadata("IncludeAssets");
return excludedAssets?.Contains("runtime") == true || excludedAssets?.Contains("all") == true ||
(!string.IsNullOrEmpty(includedAssets) && !includedAssets.Contains("runtime") && !includedAssets.Contains("all"));
};

builder = builder
.WithMainProjectInDepsFile(IncludeMainProject)
.WithReferenceAssemblies(referenceAssemblyInfos)
.WithDirectReferences(directReferences)
.WithDependencyReferences(dependencyReferences)
.WithReferenceProjectInfos(referenceProjects)
.WithExcludeFromPublishAssets(PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences))
.WithExcludeFromPublishAssets(PackageReferenceConverter.GetPackageIds(AllPackageReferences?.Where(ShouldNotBeInDepsFile)))
.WithRuntimePackAssets(runtimePackAssets)
.WithCompilationOptions(compilationOptions)
.WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Microsoft.NET.Build.Tasks
{
internal static class PackageReferenceConverter
{
public static IEnumerable<string> GetPackageIds(ITaskItem[] packageReferences)
public static IEnumerable<string> GetPackageIds(IEnumerable<ITaskItem> packageReferences)
{
if (packageReferences == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,7 @@ Copyright (c) .NET Foundation. All rights reserved.
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
RuntimeFrameworks="@(RuntimeFramework)"
CompilerOptions="@(DependencyFileCompilerOptions)"
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
AllPackageReferences="@(PackageReference)"
RuntimeStorePackages="@(RuntimeStorePackages)"
CompileReferences="@(ResolvedCompileFileDefinitions)"
ResolvedNuGetFiles="@(_ResolvedNuGetFilesForPublish)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ Copyright (c) .NET Foundation. All rights reserved.
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
RuntimeFrameworks="@(RuntimeFramework)"
CompilerOptions="@(DependencyFileCompilerOptions)"
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
AllPackageReferences="@(PackageReference)"
CompileReferences="@(ResolvedCompileFileDefinitions)"
ResolvedNuGetFiles="@(NativeCopyLocalItems);@(ResourceCopyLocalItems);@(RuntimeCopyLocalItems)"
UserRuntimeAssemblies="@(UserRuntimeAssembly)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ public void PackageReferences_with_private_assets_do_not_appear_in_deps_file(str
}
else
{
dependencyContext.CompileLibraries.Any(l => l.Name.Equals("Microsoft.AspNetCore.App")).Should().BeFalse();
dependencyContext.CompileLibraries.Any(l => l.Name.Equals("Microsoft.AspNetCore.App")).Should().BeTrue();
dependencyContext.CompileLibraries.Any(l => l.Name.Equals("Microsoft.AspNetCore")).Should().BeFalse();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" ExcludeAssets="runtime"/>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.6" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>
Expand Down
Loading