Skip to content
This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Commit a2b2c58

Browse files
committed
By default, don't include a dependency reference to NuGetizer itself
Fixes NuGet/Home#5109
1 parent c9c2312 commit a2b2c58

3 files changed

Lines changed: 60 additions & 16 deletions

File tree

src/Build/NuGet.Build.Packaging.Tasks/NuGet.Build.Packaging.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ Copyright (c) .NET Foundation. All rights reserved.
282282
<Kind>None</Kind>
283283
</PackageFile>
284284

285-
<PackageFile Include="@(PackageReference)">
285+
<PackageFile Include="@(PackageReference)" Condition="'%(Identity)' != 'NuGet.Build.Packaging'">
286286
<Kind>Dependency</Kind>
287287
</PackageFile>
288288

src/Build/NuGet.Build.Packaging.Tests/Builder.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,18 @@ public static partial class Builder
2020
const string ToolsVersion = "14.0";
2121
#endif
2222

23-
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
23+
public static BuildResult Build(ProjectInstance project, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
2424
{
25-
if (!Path.IsPathRooted(projectOrSolution))
26-
projectOrSolution = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, projectOrSolution);
27-
28-
if (!File.Exists(projectOrSolution))
29-
throw new FileNotFoundException($"Project or solution to build {projectOrSolution} was not found.", projectOrSolution);
25+
properties = properties ?? new Dictionary<string, string>();
3026

3127
// Without this, builds end up running in process and colliding with each other,
3228
// especially around the current directory used to resolve relative paths in projects.
3329
//Environment.SetEnvironmentVariable("MSBUILDNOINPROCNODE", "1", EnvironmentVariableTarget.Process);
3430
using (var manager = new BuildManager(Guid.NewGuid().ToString()))
3531
{
36-
properties = properties ?? new Dictionary<string, string>();
37-
38-
// If file is not a solution, build up a fake solution configuration so P2P references just work
39-
if (Path.GetExtension(projectOrSolution) != ".sln")
40-
AddSolutionConfiguration(projectOrSolution, properties);
41-
42-
var request = new BuildRequestData(projectOrSolution, properties, ToolsVersion, targets.Split(','), null);
32+
var request = new BuildRequestData(project, targets.Split(','), null);
4333
var parameters = new BuildParameters
44-
{
34+
{
4535
GlobalProperties = properties,
4636
DisableInProcNode = !Debugger.IsAttached,
4737
EnableNodeReuse = false,
@@ -61,6 +51,25 @@ public static BuildResult Build(string projectOrSolution, string targets, Dictio
6151
}
6252
}
6353

54+
public static BuildResult Build(string projectOrSolution, string targets, Dictionary<string, string> properties = null, ILogger logger = null)
55+
{
56+
if (!Path.IsPathRooted(projectOrSolution))
57+
projectOrSolution = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, projectOrSolution);
58+
59+
if (!File.Exists(projectOrSolution))
60+
throw new FileNotFoundException($"Project or solution to build {projectOrSolution} was not found.", projectOrSolution);
61+
62+
properties = properties ?? new Dictionary<string, string>();
63+
64+
// If file is not a solution, build up a fake solution configuration so P2P references just work
65+
if (Path.GetExtension(projectOrSolution) != ".sln")
66+
AddSolutionConfiguration(projectOrSolution, properties);
67+
68+
var projectInstance = new ProjectInstance(projectOrSolution, properties, ToolsVersion);
69+
70+
return Build(projectInstance, targets, properties, logger);
71+
}
72+
6473
static void AddSolutionConfiguration(string projectFile, Dictionary<string, string> properties)
6574
{
6675
var collection = new ProjectCollection(properties);

src/Build/NuGet.Build.Packaging.Tests/TargetsTests.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
using System.Collections.Generic;
2+
using System.IO;
3+
using System.Reflection;
4+
using Microsoft.Build.Construction;
25
using Microsoft.Build.Evaluation;
6+
using Microsoft.Build.Execution;
7+
using Microsoft.Build.Framework;
38
using Xunit;
9+
using Xunit.Abstractions;
410

511
namespace NuGet.Build.Packaging
612
{
713
public class TargetsTests
814
{
15+
ITestOutputHelper output;
16+
17+
public TargetsTests(ITestOutputHelper output) => this.output = output;
18+
919
[Fact]
1020
public void IncludeFrameworkReferencesInPackage_defaults_to_false_for_build_primary_output()
1121
{
@@ -71,6 +81,31 @@ public void PackOnBuild_defaults_to_true_for_compat_GeneratePackageOnBuild_true(
7181
Assert.Equal("true", project.GetPropertyValue("PackOnBuild"));
7282
}
7383

74-
84+
[Fact]
85+
public void package_contents_never_includes_nugetizer_package_reference()
86+
{
87+
var xml = ProjectRootElement.Create(Path.Combine(Directory.GetCurrentDirectory(), MethodBase.GetCurrentMethod().Name));
88+
xml.AddImport(@"Scenarios\Scenario.props");
89+
xml.AddImport(@"Scenarios\Scenario.targets");
90+
xml.AddItemGroup()
91+
.AddItem("PackageReference", "NuGet.Build.Packaging", new[] { new KeyValuePair<string, string>("Version", "*") });
92+
93+
xml.Save();
94+
95+
var project = new ProjectInstance(xml);
96+
97+
var result = Builder.Build(project, "GetPackageContents");
98+
99+
Assert.Equal(BuildResultCode.Success, result.OverallResult);
100+
Assert.Equal(TargetResultCode.Success, result["GetPackageContents"].ResultCode);
101+
102+
var items = result["GetPackageContents"].Items;
103+
104+
Assert.DoesNotContain(items, item => item.Matches(new
105+
{
106+
Kind = PackageItemKind.Dependency,
107+
Identity = "NuGet.Build.Packaging",
108+
}));
109+
}
75110
}
76111
}

0 commit comments

Comments
 (0)