Skip to content

Commit

Permalink
Ensure transitive dependencies are properly resolved for inference
Browse files Browse the repository at this point in the history
.NET 7.0 SDK changed from:

```xml
    <ResolvePackageDependencies
      ProjectPath="$(MSBuildProjectFullPath)"
      ProjectAssetsFile="$(ProjectAssetsFile)"
      ProjectLanguage="$(Language)"
      EmitLegacyAssetsFileItems="$(EmitLegacyAssetsFileItems)"
      TargetFramework="$(TargetFramework)"
      ContinueOnError="ErrorAndContinue">

      <Output TaskParameter="PackageDefinitions" ItemName="PackageDefinitions" />
      <Output TaskParameter="PackageDependencies" ItemName="PackageDependencies" />

      <!-- These outputs only produced when EmitLegacyAssetsFileItems is true -->
      <Output TaskParameter="TargetDefinitions" ItemName="TargetDefinitions" />
      <Output TaskParameter="FileDefinitions" ItemName="FileDefinitions" />
      <Output TaskParameter="FileDependencies" ItemName="FileDependencies" />
    </ResolvePackageDependencies>
```

to:

```xml
    <ResolvePackageDependencies
      ProjectPath="$(MSBuildProjectFullPath)"
      ProjectAssetsFile="$(ProjectAssetsFile)"
      ProjectLanguage="$(Language)"
      TargetFramework="$(TargetFramework)"
      ContinueOnError="ErrorAndContinue"
      Condition="'$(EmitLegacyAssetsFileItems)' == 'true'">

      <Output TaskParameter="PackageDefinitions" ItemName="PackageDefinitions" />
      <Output TaskParameter="PackageDependencies" ItemName="PackageDependencies" />
      <Output TaskParameter="TargetDefinitions" ItemName="TargetDefinitions" />
      <Output TaskParameter="FileDefinitions" ItemName="FileDefinitions" />
      <Output TaskParameter="FileDependencies" ItemName="FileDependencies" />
    </ResolvePackageDependencies>
```

Since the SDK now conditions the execution of the resolve to the value of `EmitLegacyAssetsFileItems`, we need to explicitly set it.

Since this was likely done for performance reasons, only turn on when package inference is active, since we don't use that anywhere else.
  • Loading branch information
kzu committed Feb 24, 2023
1 parent ed1106f commit 2ca40f3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Copyright (c) .NET Foundation. All rights reserved.

<_OutputFullPath Condition="$([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath)</_OutputFullPath>
<_OutputFullPath Condition="'$(_OutputFullPath)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))\$(OutputPath)</_OutputFullPath>

<!-- Ensure built-in RunResolvePackageDependencies target emits stuff we need for inference of transitive dependencies -->
<EmitLegacyAssetsFileItems>true</EmitLegacyAssetsFileItems>
</PropertyGroup>

<PropertyGroup Label="Package Readme" Condition="'$(PackReadme)' == 'true' and '$(IsPackable)' == 'true'">
Expand Down
26 changes: 26 additions & 0 deletions src/NuGetizer.Tests/InlineProjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,5 +774,31 @@ public void when_packing_dependencies_then_can_include_exclude_assets()
ExcludeAssets = "build"
}));
}

[Fact]
public void when_private_assets_then_packs_transitively()
{
var result = Builder.BuildProject(
"""
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>true</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" PrivateAssets="all" />
</ItemGroup>
</Project>
""", output: output);

result.AssertSuccess(output);

Assert.Contains(result.Items, item => item.Matches(new
{
NuGetPackageId = "Microsoft.Extensions.Configuration.Abstractions",
PackFolder = "Lib",
}));
}
}
}

0 comments on commit 2ca40f3

Please sign in to comment.