This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add private assets from package reference
Fixes NuGet/Home#5103 This is only performed for resolved NuGet artifacts that have one of the specified values in the referenced NuGet specification at https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files#controlling-dependency-assets. This minimizes the impact of the new inference and preserves existing behavior.
- Loading branch information
Showing
13 changed files
with
195 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...et.Build.Packaging.Tests/Scenarios/given_a_library_with_private_assets_reference/a.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Scenario.props))\Scenario.props" /> | ||
<PropertyGroup> | ||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Mono.Options"> | ||
<Version>*</Version> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="Newtonsoft.Json"> | ||
<Version>*</Version> | ||
<PrivateAssets>lib</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="xunit"> | ||
<Version>*</Version> | ||
</PackageReference> | ||
</ItemGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), Scenario.targets))\Scenario.targets" /> | ||
</Project> |
84 changes: 84 additions & 0 deletions
84
src/Build/NuGet.Build.Packaging.Tests/given_a_library_with_private_assets_reference.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System.Linq; | ||
using Microsoft.Build.Execution; | ||
using Microsoft.Build.Framework; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NuGet.Build.Packaging | ||
{ | ||
public class given_a_library_with_private_assets_reference | ||
{ | ||
ITestOutputHelper output; | ||
|
||
public given_a_library_with_private_assets_reference(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
} | ||
|
||
[Fact] | ||
public void when_getting_package_contents_then_contains_private_assets_as_primary_output() | ||
{ | ||
Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), target: "Restore", output: output); | ||
var result = Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), output: output); | ||
|
||
result.AssertSuccess(output); | ||
|
||
Assert.DoesNotContain(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Dependency, | ||
Identity = "Mono.Options", | ||
})); | ||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Lib, | ||
Filename = "Mono.Options", | ||
NuGetSourceType = "Package", | ||
NuGetPackageId = "Mono.Options", | ||
})); | ||
} | ||
|
||
[Fact] | ||
public void when_getting_package_contents_then_contains_private_lib_assets_as_primary_output_and_also_package_reference() | ||
{ | ||
Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), target: "Restore", output: output); | ||
var result = Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), output: output); | ||
|
||
result.AssertSuccess(output); | ||
|
||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Dependency, | ||
Identity = "Newtonsoft.Json", | ||
})); | ||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Lib, | ||
Filename = "Newtonsoft.Json", | ||
NuGetSourceType = "Package", | ||
NuGetPackageId = "Newtonsoft.Json", | ||
})); | ||
} | ||
|
||
[Fact] | ||
public void when_getting_package_contents_then_contains_dependency_for_non_private_assets_reference() | ||
{ | ||
Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), target: "Restore", output: output); | ||
var result = Builder.BuildScenario(nameof(given_a_library_with_private_assets_reference), output: output); | ||
|
||
result.AssertSuccess(output); | ||
|
||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Dependency, | ||
Identity = "xunit", | ||
})); | ||
Assert.DoesNotContain(result.Items, item => item.Matches(new | ||
{ | ||
Kind = PackageItemKind.Lib, | ||
Filename = "xunit", | ||
NuGetSourceType = "Package", | ||
NuGetPackageId = "xunit", | ||
})); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters