-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Never infer implicit reference for existing direct reference
We should never traverse and infer implicit transitive dependencies for packages that are already directly referenced by the project. This fixes the scenario where the project has a direct dependency to a package and another direct dependency has a transitive dependency to the same one. By inferring the latter as an implicit dependency, we overwrite the pack attributes of the former.
- Loading branch information
Showing
2 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Logging.StructuredLogger; | ||
using Microsoft.Build.Utilities; | ||
using NuGet.Packaging.Signing; | ||
using NuGetizer.Tasks; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using Metadata = System.Collections.Generic.Dictionary<string, string>; | ||
|
||
namespace NuGetizer; | ||
|
||
public class InferImplicitPackageReferenceTests | ||
{ | ||
readonly ITestOutputHelper output; | ||
readonly MockBuildEngine engine; | ||
|
||
public InferImplicitPackageReferenceTests(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
engine = new MockBuildEngine(output); | ||
} | ||
|
||
[Fact] | ||
public void when_file_has_no_kind_then_logs_error_code() | ||
{ | ||
var task = new InferImplicitPackageReference | ||
{ | ||
BuildEngine = engine, | ||
PackageReferences = new ITaskItem[] | ||
{ | ||
new TaskItem("NuGetizer", new Metadata | ||
{ | ||
{ "Version", "1.0.0" }, | ||
{ "PrivateAssets", "all" }, | ||
}), | ||
new TaskItem("Devlooped.SponsorLink", new Metadata | ||
{ | ||
{ "Version", "1.0.0" }, | ||
}) | ||
}, | ||
PackageDependencies = new ITaskItem[] | ||
{ | ||
new TaskItem("NuGetizer", new Metadata | ||
{ | ||
{ "ParentPackage", "" }, | ||
}), | ||
new TaskItem("Devlooped.SponsorLink", new Metadata | ||
{ | ||
{ "ParentPackage", "" }, | ||
}), | ||
new TaskItem("NuGetizer/1.0.0", new Metadata | ||
{ | ||
{ "ParentTarget", "netstandard2.0" }, | ||
{ "ParentPackage", "" }, | ||
}), | ||
new TaskItem("Devlooped.SponsorLink/1.0.0", new Metadata | ||
{ | ||
{ "ParentTarget", "netstandard2.0" }, | ||
{ "ParentPackage", "NuGetizer/1.0.0" }, | ||
}) | ||
} | ||
}; | ||
|
||
Assert.True(task.Execute()); | ||
Assert.Empty(task.ImplicitPackageReferences); | ||
} | ||
} |