-
-
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.
Additional fix for --no-build in pack with transitive references
Turns out that the .NET SDK lifts transitive project references as direct references (without any additional metadata), and this causes the second-level dependency from being built unexpectedly (see dotnet/sdk#478 and dotnet/project-system#199). Since we don't want to disrupt the IDE (BuildingInsideVisualStudio) and we only want to fix this for the very specific case of running from the CLI `dotnet pack --no-build`, we make the fix very constrained for that scenario. We check for `NoBuild` but ALSO for `_IsPacking`, which is passed by the `dotnet pack` command. This ensures minimal impact in all other scenarios, since we're essentially turning off a built-in behavior in the SDK that has explicit side-effects (by design and desirable) and we should preserve. #Fixes 501
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 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
15 changes: 15 additions & 0 deletions
15
src/NuGetizer.Tests/Scenarios/given_transitive_projects/Project1.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Scenario.props, $(MSBuildThisFileDirectory)))" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<PackageId>Foo</PackageId> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="Project2.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/NuGetizer.Tests/Scenarios/given_transitive_projects/Project2.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Scenario.props, $(MSBuildThisFileDirectory)))" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="Project3.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
15 changes: 15 additions & 0 deletions
15
src/NuGetizer.Tests/Scenarios/given_transitive_projects/Project3.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,15 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="$([MSBuild]::GetPathOfFileAbove(Scenario.props, $(MSBuildThisFileDirectory)))" /> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="NuGetizer" Version="1.2.2" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,55 @@ | ||
using System.Linq; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NuGetizer | ||
{ | ||
public class given_transitive_projects | ||
{ | ||
readonly ITestOutputHelper output; | ||
|
||
public given_transitive_projects(ITestOutputHelper output) | ||
{ | ||
this.output = output; | ||
using var disable = OpenBuildLogAttribute.Disable(); | ||
|
||
Builder.BuildScenario(nameof(given_transitive_projects), target: "Restore", projectName: "Project1") | ||
.AssertSuccess(output); | ||
|
||
Builder.BuildScenario(nameof(given_transitive_projects), target: "Build", projectName: "Project1") | ||
.AssertSuccess(output); | ||
} | ||
|
||
[OpenBuildLog] | ||
[Fact] | ||
public void when_pack_no_build_then_succeeds() | ||
{ | ||
var result = Builder.BuildScenario(nameof(given_transitive_projects), | ||
projectName: "Project1", | ||
// These are the properties passed by dotnet pack --no-build | ||
properties: new { NoBuild = "true", _IsPacking = "true" }, | ||
target: "GetPackageContents,Pack"); | ||
|
||
result.AssertSuccess(output); | ||
|
||
Assert.True(result.BuildResult.HasResultsForTarget("GetPackageContents")); | ||
|
||
var items = result.BuildResult.ResultsByTarget["GetPackageContents"]; | ||
|
||
Assert.Contains(items.Items, item => item.Matches(new | ||
{ | ||
PackagePath = "lib/net8.0/Project1.dll" | ||
})); | ||
|
||
Assert.Contains(items.Items, item => item.Matches(new | ||
{ | ||
PackagePath = "lib/net8.0/Project2.dll" | ||
})); | ||
|
||
Assert.Contains(items.Items, item => item.Matches(new | ||
{ | ||
PackagePath = "lib/net8.0/Project3.dll" | ||
})); | ||
} | ||
} | ||
} |