Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/NuGetizer.Tasks/NuGetizer.Inference.targets
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<PackFrameworkReferences Condition="'$(PackFrameworkReferences)' == '' and '$(IsPackagingProject)' != 'true' and '$(PackFolder)' == 'lib'">true</PackFrameworkReferences>
<!-- When PackFolder is build/buildTransitive, we default to packing None since it's most intuitive in that case -->
<PackNone Condition="'$(PackNone)' == '' and ('$(PackFolder)' == 'build' or '$(PackFolder)' == 'buildTransitive')">true</PackNone>
<!-- When in a packaging project, default to packing None since it's most intuitive for authoring/packaging projects -->
<PackNone Condition="'$(PackNone)' == '' and '$(IsPackagingProject)' == 'true'">true</PackNone>

<_OutputFullPath Condition="$([System.IO.Path]::IsPathRooted($(OutputPath)))">$(OutputPath)</_OutputFullPath>
<_OutputFullPath Condition="'$(_OutputFullPath)' == ''">$(MSBuildProjectDirectory.TrimEnd('\'))\$(OutputPath)</_OutputFullPath>
Expand Down Expand Up @@ -236,6 +238,28 @@ Copyright (c) .NET Foundation. All rights reserved.
</ItemGroup>
</Target>

<!--
When PackReadme=false, explicitly exclude the readme file from being packed as a None item.
This is necessary because PackNone=true in packaging projects would otherwise include it.
-->
<Target Name="_ExcludeReadmeWhenPackReadmeFalse"
BeforeTargets="_CollectInferenceCandidates"
Condition="'$(PackReadme)' == 'false'">
<PropertyGroup>
<!-- Compute the readme filename, defaulting to readme.md if not specified -->
<_PackageReadmeFilename Condition="'$(PackageReadmeFile)' != ''">$(PackageReadmeFile)</_PackageReadmeFilename>
<_PackageReadmeFilename Condition="'$(PackageReadmeFile)' == ''">readme.md</_PackageReadmeFilename>
</PropertyGroup>
<ItemGroup>
<None Update="@(None)"
Pack="false"
Condition="%(None.Identity) == '$(_PackageReadmeFilename)'" />
<Content Update="@(Content)"
Pack="false"
Condition="%(Content.Identity) == '$(_PackageReadmeFilename)'" />
</ItemGroup>
</Target>

<Target Name="_CollectInferenceCandidates" Inputs="@(PackInference)" Outputs="|%(PackInference.Identity)|">
<PropertyGroup>
<PackExclude>%(PackInference.PackExclude)</PackExclude>
Expand Down
57 changes: 57 additions & 0 deletions src/NuGetizer.Tests/given_a_packaging_project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,62 @@ public void when_readme_custom_extension_specified_then_adds_metadata_and_conten
Readme = "readme.txt",
}));
}

[Fact]
public void when_packaging_project_then_none_items_pack_by_default()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.Build.NoTargets/3.7.0'>
<PropertyGroup>
<PackageId>Packer</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
<!-- Only needed since for scenarios we set this to false. -->
<EnableDefaultItems>true</EnableDefaultItems>
</PropertyGroup>
</Project>",
"GetPackageContents", output,
files: ("Packer.targets", @"<Project />"));

result.AssertSuccess(output);
Assert.Contains(result.Items, item => item.Matches(new
{
Filename = "Packer",
Extension = ".targets",
PackFolder = "None",
}));
}

[Fact]
public void when_packaging_project_with_none_item_then_packs_without_explicit_packnone()
{
var result = Builder.BuildProject(@"
<Project Sdk='Microsoft.Build.NoTargets/3.7.0'>
<PropertyGroup>
<PackageId>MyPackage</PackageId>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<None Include='MyPackage.targets' />
<None Include='tools\install.ps1' />
</ItemGroup>
</Project>",
"GetPackageContents", output,
files: [
("MyPackage.targets", @"<Project />"),
("tools\\install.ps1", @"# Install script")
]);

result.AssertSuccess(output);
Assert.Contains(result.Items, item => item.Matches(new
{
Filename = "MyPackage",
Extension = ".targets",
}));
Assert.Contains(result.Items, item => item.Matches(new
{
Filename = "install",
Extension = ".ps1",
}));
}
}
}