Skip to content

Commit

Permalink
When IsPackable=true, default PackageId=AssemblyName
Browse files Browse the repository at this point in the history
This matches the behavior in SDK pack and makes sense as a default when IsPackable is set, instead of requiring explicit PackageId,
  • Loading branch information
kzu committed Oct 4, 2020
1 parent 4ed4d90 commit 3db4b89
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.Shared.targets
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Copyright (c) .NET Foundation. All rights reserved.
</PropertyGroup>

<PropertyGroup Label="Hidden">
<!-- Matches the SDK Pack default when set to true. -->
<PackageId Condition="'$(IsPackable)' == 'true' and '$(PackageId)' == ''">$(AssemblyName)</PackageId>

<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' != ''">true</IsPackable>
<IsPackable Condition="'$(IsPackable)' == '' and '$(PackageId)' == ''">false</IsPackable>
<!-- When the project is building a package, AssignPackagePath always assigns a PackagePath, regardless of the project PackageId -->
Expand Down
35 changes: 35 additions & 0 deletions src/NuGetizer.Tests/given_an_empty_library.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,41 @@ public class given_an_empty_library

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

[Fact]
public void when_is_packable_true_then_package_id_defaults_to_assembly_name()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
<IsPackable>true</IsPackable>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>", output: output);

result.AssertSuccess(output);
Assert.Contains(result.Items, item => item.Matches(new
{
PackFolder = PackFolderKind.Metadata
}));
}

[Fact]
public void when_no_is_packable_and_no_package_id_then_defaults_to_non_packable()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.NET.Sdk'>
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</Project>", output: output);

result.AssertSuccess(output);
Assert.DoesNotContain(result.Items, item => item.Matches(new
{
PackFolder = PackFolderKind.Metadata
}));
}

[Fact]
public void when_getting_package_contents_then_includes_output_assembly()
{
Expand Down

0 comments on commit 3db4b89

Please sign in to comment.