Skip to content

Commit e8b0802

Browse files
authored
Improve PackageId/IsPackable defaulting
By preserving the project-defined PackageId and restoring it (potentially empty), we respect the project's choice. Also, it makes no sense for an empty PackageId to have IsPackable after pack imports+restore, so we default it back to false in that case.
1 parent 6e24389 commit e8b0802

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

src/Directory.Build.targets

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,18 @@
3232
<IsPackable Condition="'$(PackageId)' != ''">true</IsPackable>
3333
</PropertyGroup>
3434

35+
<PropertyGroup>
36+
<!-- Save original PackageId to restore post-import -->
37+
<_PackageId>$(PackageId)</_PackageId>
38+
</PropertyGroup>
39+
3540
<Import Project="$(NuGetBuildTasksPackTargets)" Condition="Exists('$(NuGetBuildTasksPackTargets)')"/>
3641

3742
<PropertyGroup>
3843
<!-- Revert the forced PackageId by the NuGet SDK targets for non-packable projects, see https://github.com/NuGet/Home/issues/14928 -->
39-
<PackageId Condition="'$(IsPackable)' == 'false'"></PackageId>
44+
<PackageId Condition="'$(IsPackable)' == 'false'">$(_PackageId)</PackageId>
45+
<!-- If no PackageId was originally provided, ensure IsPackable is false -->
46+
<IsPackable Condition="'$(_PackageId)' == ''">false</IsPackable>
4047
</PropertyGroup>
4148

4249
<ItemGroup Condition="'$(IsPackable)' == 'true'" Label="NuGet">

0 commit comments

Comments
 (0)