Skip to content

Commit

Permalink
Automatically infer PackAsTool when ToolCommandName is used
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Aug 7, 2024
1 parent 04a6a78 commit 2f0d0ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<UsingTask TaskName="NuGetizer.Tasks.EvaluateWildcards" AssemblyFile="NuGetizer.Tasks.dll" />

<PropertyGroup>
<!-- When ToolCommandName is set, infer that packaging should default to PackAsTool -->
<PackAsTool Condition="'$(PackAsTool)' == '' and '$(ToolCommandName)' != ''">true</PackAsTool>

<!-- The PackFolder of primary output (build, symbols, doc and satellite assemblies) set if PackBuildOutput = true -->
<PackFolder Condition="'$(PackFolder)' == ''">lib</PackFolder>

Expand Down
27 changes: 27 additions & 0 deletions src/NuGetizer.Tests/given_a_tool_project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ public void when_pack_as_tool_then_packs_no_dependencies()
}));
}

[Fact]
public void when_toolcommand_then_packs_as_tool_with_no_dependencies()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.Build.NoTargets/3.7.0'>
<PropertyGroup>
<PackageId>MyTool</PackageId>
<TargetFramework>net8.0</TargetFramework>
<ToolCommandName>mycommand</ToolCommandName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include='Microsoft.Extensions.DependencyModel' Version='8.0.0' />
</ItemGroup>
</Project>",
"GetPackageContents", output);

result.AssertSuccess(output);
Assert.DoesNotContain(result.Items, item => item.Matches(new
{
Identity = "Microsoft.Extensions.DependencyModel"
}));
Assert.Contains(result.Items, item => item.Matches(new
{
PackageFile = "Microsoft.Extensions.DependencyModel.dll"
}));
}

[Fact]
public void when_pack_as_tool_then_packs_dotnet_tool_runtime_assets()
{
Expand Down

0 comments on commit 2f0d0ca

Please sign in to comment.