-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve compatibility with SDK Pack for tools
This brings nugetizer pretty much to parity with SDK Pack for CLI tools too :). We leverage the SDK tool packing targets to determine the files to pack, but otherwise preserve nugetizer's inference and packing behavior. Best of both worlds! The new `InferToolContents` target is the one that transforms the `PackTool` target's `TfmSpecificPackageFile` into our own `None` items for packing. It can also be extended to trim the tool's contents via a custom target that removes items, such as:: ```xml <Target Name="TrimRuntimes" AfterTargets="InferToolContents"> <ItemGroup> <None Remove="@(None)" Condition="$([MSBuild]::ValueOrDefault('%(None.PackagePath)', '').Contains('/runtimes/'))" /> </ItemGroup> </Target> ``` (this target would remove all runtimes from the tool package, but otherwise preserve the package contents). Fixes #134
- Loading branch information
Showing
3 changed files
with
129 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace NuGetizer | ||
{ | ||
public class given_a_tool_project | ||
{ | ||
ITestOutputHelper output; | ||
|
||
public given_a_tool_project(ITestOutputHelper output) => this.output = output; | ||
|
||
[Fact] | ||
public void when_pack_as_tool_then_packs_no_dependencies() | ||
{ | ||
var result = Builder.BuildProject(@" | ||
<Project Sdk='Microsoft.Build.NoTargets/3.5.0'> | ||
<PropertyGroup> | ||
<PackageId>MyTool</PackageId> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<PackFolder>tools</PackFolder> | ||
<PackAsTool>true</PackAsTool> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include='Microsoft.Extensions.DependencyModel' Version='6.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() | ||
{ | ||
var result = Builder.BuildProject(@" | ||
<Project Sdk='Microsoft.NET.Sdk'> | ||
<PropertyGroup> | ||
<AssemblyName>MyTool</AssemblyName> | ||
<PackageId>MyTool</PackageId> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<PackFolder>tools</PackFolder> | ||
<PackAsTool>true</PackAsTool> | ||
</PropertyGroup> | ||
</Project>", | ||
"GetPackageContents", output); | ||
|
||
result.AssertSuccess(output); | ||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
PackageFile = "DotnetToolSettings.xml" | ||
})); | ||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
PackageFile = "MyTool.deps.json" | ||
})); | ||
} | ||
|
||
[Fact] | ||
public void when_pack_folder_tool_but_no_pack_as_tool_then_packs_dependencies_normally() | ||
{ | ||
var result = Builder.BuildProject(@" | ||
<Project Sdk='Microsoft.Build.NoTargets/3.5.0'> | ||
<PropertyGroup> | ||
<PackageId>MyTool</PackageId> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<PackFolder>tools</PackFolder> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include='Microsoft.Extensions.DependencyModel' Version='6.0.0' /> | ||
</ItemGroup> | ||
</Project>", | ||
"GetPackageContents", output); | ||
|
||
result.AssertSuccess(output); | ||
Assert.Contains(result.Items, item => item.Matches(new | ||
{ | ||
Identity = "Microsoft.Extensions.DependencyModel" | ||
})); | ||
} | ||
} | ||
} |