Skip to content

Commit 3db4b89

Browse files
committed
When IsPackable=true, default PackageId=AssemblyName
This matches the behavior in SDK pack and makes sense as a default when IsPackable is set, instead of requiring explicit PackageId,
1 parent 4ed4d90 commit 3db4b89

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/NuGetizer.Tasks/NuGetizer.Shared.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ Copyright (c) .NET Foundation. All rights reserved.
3737
</PropertyGroup>
3838

3939
<PropertyGroup Label="Hidden">
40+
<!-- Matches the SDK Pack default when set to true. -->
41+
<PackageId Condition="'$(IsPackable)' == 'true' and '$(PackageId)' == ''">$(AssemblyName)</PackageId>
42+
4043
<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' != ''">true</IsPackable>
4144
<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' == ''">false</IsPackable>
4245
<!-- When the project is building a package, AssignPackagePath always assigns a PackagePath, regardless of the project PackageId -->

src/NuGetizer.Tests/given_an_empty_library.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,41 @@ public class given_an_empty_library
1010

1111
public given_an_empty_library(ITestOutputHelper output) => this.output = output;
1212

13+
[Fact]
14+
public void when_is_packable_true_then_package_id_defaults_to_assembly_name()
15+
{
16+
var result = Builder.BuildProject(@"
17+
<Project Sdk='Microsoft.NET.Sdk'>
18+
<PropertyGroup>
19+
<IsPackable>true</IsPackable>
20+
<TargetFramework>netstandard2.0</TargetFramework>
21+
</PropertyGroup>
22+
</Project>", output: output);
23+
24+
result.AssertSuccess(output);
25+
Assert.Contains(result.Items, item => item.Matches(new
26+
{
27+
PackFolder = PackFolderKind.Metadata
28+
}));
29+
}
30+
31+
[Fact]
32+
public void when_no_is_packable_and_no_package_id_then_defaults_to_non_packable()
33+
{
34+
var result = Builder.BuildProject(@"
35+
<Project Sdk='Microsoft.NET.Sdk'>
36+
<PropertyGroup>
37+
<TargetFramework>netstandard2.0</TargetFramework>
38+
</PropertyGroup>
39+
</Project>", output: output);
40+
41+
result.AssertSuccess(output);
42+
Assert.DoesNotContain(result.Items, item => item.Matches(new
43+
{
44+
PackFolder = PackFolderKind.Metadata
45+
}));
46+
}
47+
1348
[Fact]
1449
public void when_getting_package_contents_then_includes_output_assembly()
1550
{

0 commit comments

Comments
 (0)