PSResourceGet icon indicating copy to clipboard operation
PSResourceGet copied to clipboard

Set or expose the NoDefaultExcludes nuget parameter in Publish-Module

Open GordonFreemanK opened this issue 2 years ago • 1 comments

Summary of the new feature / enhancement

nuget pack (and by transition dotnet pack and Publish-Module) have a default behaviour of ignoring *.nuspec files and .* files and folders. As a result, when publishing PowerShell modules those files also get ignored, which can get in the way depending of what your workflow is (in my case, I'm trying to ship a default ExifTool configuration file).

This can be overriden in nuget and dotnet pack with the CLI switch / csproj property NoDefaultExcludes. The way Publish-Module works though, there is no way to override this, as the module creates a temporary csproj file which the module user has no control over.

It would be nice to set or at least expose this switch in the Publish-Module Cmdlet.

More info: The verbose logging from Publish-Module when the folder contains a filtered file:

VERBOSE:        C:\Program Files\dotnet\sdk\6.0.201\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): warning NU5119: File 'C:\Users\xxx\AppData\Local\Temp\222345117\GFK.Image\ExifTool\.ExifTool_config' was
not added to the package. Files and folders starting with '.' or ending with '.nupkg' are excluded by default. To include this file, use -NoDefaultExcludes from the commandline [C:\Users\xxx\AppData\Local\Temp\cba5a149-c53d-420c-9
6ff-bb9c4a63df02\Temp.csproj]

Proposed technical implementation details (optional)

I was able to publish a module including those files by modifying the PowerShellGet module on my local environment myself as follows (specifically the <NoDefaultExcludes>true</NoDefaultExcludes> bit). Feels like it would just be a matter of condtionally control this with a Cmdlet switch parameter.

$CsprojContent = @"
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <AssemblyName>NotUsed</AssemblyName>
    <Description>Temp project used for creating nupkg file.</Description>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <IsPackable>true</IsPackable>
    <NoDefaultExcludes>true</NoDefaultExcludes>
</PropertyGroup>
</Project>
"@

GordonFreemanK avatar Apr 03 '22 22:04 GordonFreemanK