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

Revert private assets in deps.json change (#45259) #46182

Merged
merged 1 commit into from
Jan 23, 2025
Merged
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
38 changes: 0 additions & 38 deletions src/Tasks/Microsoft.NET.Build.Tasks/DependencyContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class DependencyContextBuilder
private Dictionary<string, List<ReferenceInfo>> _compileReferences;
private Dictionary<string, List<ResolvedFile>> _resolvedNuGetFiles;
private Dictionary<string, SingleProjectInfo> _referenceProjectInfos;
private IEnumerable<string> _excludeFromPublishPackageIds;
private Dictionary<string, List<RuntimePackAssetInfo>> _runtimePackAssets;
private CompilationOptions _compilationOptions;
private string _referenceAssembliesPath;
Expand Down Expand Up @@ -205,12 +204,6 @@ public DependencyContextBuilder WithReferenceProjectInfos(Dictionary<string, Sin
return this;
}

public DependencyContextBuilder WithExcludeFromPublishAssets(IEnumerable<string> excludeFromPublishPackageIds)
{
_excludeFromPublishPackageIds = excludeFromPublishPackageIds;
return this;
}

public DependencyContextBuilder WithMainProjectInDepsFile(bool includeMainProjectInDepsFile)
{
_includeMainProjectInDepsFile = includeMainProjectInDepsFile;
Expand Down Expand Up @@ -819,37 +812,6 @@ private void CalculateExcludedLibraries()
{
_dependencyLibraries[packageToExcludeFromRuntime].ExcludeFromRuntime = true;
}

// Include transitive dependencies of all top-level dependencies
Dictionary<string, DependencyLibrary> includedDependencies = new(StringComparer.OrdinalIgnoreCase);
Stack<string> dependencyListToWalk = new(_mainProjectDependencies);

while (dependencyListToWalk.Count != 0)
{
var dependencyName = dependencyListToWalk.Pop();
// There may not be a library in the assets file if a referenced project has
// PrivateAssets="all" for a package reference, and there is a package in the graph
// that depends on the same package.
if (!includedDependencies.ContainsKey(dependencyName) &&
_excludeFromPublishPackageIds?.Contains(dependencyName) != true &&
_dependencyLibraries.TryGetValue(dependencyName, out var dependencyLibrary))
{
includedDependencies.Add(dependencyName, dependencyLibrary);
foreach (var newDependency in _libraryDependencies[dependencyName])
{
dependencyListToWalk.Push(newDependency.Name);
}
}
}

foreach (var dependencyLibrary in _dependencyLibraries.Values)
{
if (!includedDependencies.ContainsKey(dependencyLibrary.Name))
{
dependencyLibrary.ExcludeFromCompilation = true;
dependencyLibrary.ExcludeFromRuntime = true;
}
}
}

private string GetReferenceLibraryName(ReferenceInfo reference)
Expand Down
3 changes: 0 additions & 3 deletions src/Tasks/Microsoft.NET.Build.Tasks/GenerateDepsFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ public class GenerateDepsFile : TaskBase

public ITaskItem CompilerOptions { get; set; }

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

public ITaskItem[] RuntimeStorePackages { get; set; }

// NuGet compilation assets
Expand Down Expand Up @@ -234,7 +232,6 @@ bool ShouldIncludeRuntimeAsset(ITaskItem item)
.WithDirectReferences(directReferences)
.WithDependencyReferences(dependencyReferences)
.WithReferenceProjectInfos(referenceProjects)
.WithExcludeFromPublishAssets(PackageReferenceConverter.GetPackageIds(ExcludeFromPublishPackageReferences))
.WithRuntimePackAssets(runtimePackAssets)
.WithCompilationOptions(compilationOptions)
.WithReferenceAssembliesPath(FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,6 @@ Copyright (c) .NET Foundation. All rights reserved.
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
RuntimeFrameworks="@(RuntimeFramework)"
CompilerOptions="@(DependencyFileCompilerOptions)"
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
RuntimeStorePackages="@(RuntimeStorePackages)"
CompileReferences="@(ResolvedCompileFileDefinitions)"
ResolvedNuGetFiles="@(_ResolvedNuGetFilesForPublish)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ Copyright (c) .NET Foundation. All rights reserved.
PlatformLibraryName="$(MicrosoftNETPlatformLibrary)"
RuntimeFrameworks="@(RuntimeFramework)"
CompilerOptions="@(DependencyFileCompilerOptions)"
ExcludeFromPublishPackageReferences="@(_ExcludeFromPublishPackageReference)"
CompileReferences="@(ResolvedCompileFileDefinitions)"
ResolvedNuGetFiles="@(NativeCopyLocalItems);@(ResourceCopyLocalItems);@(RuntimeCopyLocalItems)"
UserRuntimeAssemblies="@(UserRuntimeAssembly)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,32 +225,6 @@ public void It_can_preserve_compilation_context_and_reference_netstandard_librar
}
}

[Theory]
[InlineData("RazorSimpleMvc22", "netcoreapp2.2", "SimpleMvc22")]
[InlineData("DesktopReferencingNetStandardLibrary", "net46", "Library")]
public void PackageReferences_with_private_assets_do_not_appear_in_deps_file(string asset, string targetFramework, string exeName)
{
var testAsset = _testAssetsManager
.CopyTestAsset(asset)
.WithSource();

var buildCommand = new BuildCommand(testAsset);
buildCommand.Execute().Should().Pass();

using (var depsJsonFileStream = File.OpenRead(Path.Combine(buildCommand.GetOutputDirectory(targetFramework).FullName, exeName + ".deps.json")))
{
var dependencyContext = new DependencyContextJsonReader().Read(depsJsonFileStream);
if (asset.Equals("DesktopReferencingNetStandardLibrary"))
{
dependencyContext.CompileLibraries.Any(l => l.Name.Equals("Library")).Should().BeTrue();
}
else
{
dependencyContext.CompileLibraries.Any(l => l.Name.Equals("Microsoft.AspNetCore.App")).Should().BeFalse();
}
}
}

[WindowsOnlyFact]
public void It_resolves_assembly_conflicts_with_a_NETFramework_library()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,9 @@ public void Build_ProducesDepsFileWithCompilationContext_ButNoReferences()
depsFile.Should().Exist();
var dependencyContext = ReadDependencyContext(depsFile.FullName);

if (TargetFramework.Equals("netcoreapp2.2"))
{
// Ensure compile references from a PrivateAssets="all" PackageReference don't exist
var packageReference = dependencyContext.CompileLibraries.FirstOrDefault(l => l.Name == "System.Runtime.CompilerServices.Unsafe", defaultValue: null);
packageReference.Should().BeNull();
}
else
{
// Ensure some compile references exist
var packageReference = dependencyContext.CompileLibraries.First(l => l.Name == "System.Runtime.CompilerServices.Unsafe");
packageReference.Assemblies.Should().NotBeEmpty();
}
// Ensure some compile references exist
var packageReference = dependencyContext.CompileLibraries.First(l => l.Name == "System.Runtime.CompilerServices.Unsafe");
packageReference.Assemblies.Should().NotBeEmpty();

var projectReference = dependencyContext.CompileLibraries.First(l => l.Name == TestProjectName);
projectReference.Assemblies.Should().NotBeEmpty();
Expand Down