Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional fix for --no-build in pack with transitive references #511

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,14 @@ Copyright (c) .NET Foundation. All rights reserved.
$(_AllProjectCapabilities.Contains('WinRTReferences')) or
$(_AllProjectCapabilities.Contains('SDKReferences'))">true</_SupportsReferences>

<!-- Very constrained scenario for CLI pack with dotnet pack -no-build, which otherwise triggers
transitive project references to be built when that's not what the user wants. -->
<DisableTransitiveProjectReferences Condition="'$(_SupportsReferences)' == 'true' and
'$(_IsPacking)' == 'true' and
'$(NoBuild)' == 'true' and
'$(BuildingInsideVisualStudio)' != 'true' and
'$(DesignTimeBuild)' != 'true'" >true</DisableTransitiveProjectReferences>

<InferPackageContentsDependsOn Condition="'$(_SupportsReferences)' == 'true'">
ResolveReferences;
_UpdatePackageReferenceVersions;
Expand Down
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>
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>
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>
53 changes: 53 additions & 0 deletions src/NuGetizer.Tests/given_transitive_projects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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);
}

[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"
}));
}
}
}
Loading