Skip to content
Closed
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
12 changes: 12 additions & 0 deletions src/code/PublishHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,18 @@ private string CreateNuspec(
}

packageElement.AppendChild(metadataElement);

// Add <files> section to explicitly include all files, including empty files and files starting with '.'
// This overrides NuGet's default exclusions which would skip .gitkeep files and empty files
XmlElement filesElement = doc.CreateElement("files", nameSpaceUri);

// Include all files from the output directory
XmlElement fileElement = doc.CreateElement("file", nameSpaceUri);
fileElement.SetAttribute("src", "**");
fileElement.SetAttribute("target", "");
filesElement.AppendChild(fileElement);

packageElement.AppendChild(filesElement);
doc.AppendChild(packageElement);

var nuspecFullName = System.IO.Path.Combine(outputDir, _pkgName + ".nuspec");
Expand Down
45 changes: 45 additions & 0 deletions test/PublishPSResourceTests/CompressPSResource.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,49 @@ Describe "Test Compress-PSResource" -tags 'CI' {
$signature.Status | Should -Be 'Valid'
}
#>

It "Compress-PSResource includes .gitkeep files and empty files" {
$version = "1.0.0"

# Create module structure with .gitkeep files
New-ModuleManifest -Path (Join-Path -Path $script:PublishModuleBase -ChildPath "$script:PublishModuleName.psd1") -ModuleVersion $version -Description "$script:PublishModuleName module"

# Create Public and Private directories with .gitkeep files
$publicDir = Join-Path -Path $script:PublishModuleBase -ChildPath "Public"
$privateDir = Join-Path -Path $script:PublishModuleBase -ChildPath "Private"
New-Item -Path $publicDir -ItemType Directory -Force
New-Item -Path $privateDir -ItemType Directory -Force

# Create empty .gitkeep in Public
$publicGitkeep = Join-Path -Path $publicDir -ChildPath ".gitkeep"
New-Item -Path $publicGitkeep -ItemType File -Force

# Create non-empty .gitkeep in Private
$privateGitkeep = Join-Path -Path $privateDir -ChildPath ".gitkeep"
"# Placeholder file" | Out-File -FilePath $privateGitkeep -Encoding utf8

# Compress the module
Compress-PSResource -Path $script:PublishModuleBase -DestinationPath $script:repositoryPath

# Verify the nupkg was created
$nupkgPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.nupkg"
Test-Path -Path $nupkgPath | Should -Be $True

# Extract and verify .gitkeep files are present
$zipPath = Join-Path -Path $script:repositoryPath -ChildPath "$script:PublishModuleName.$version.zip"
Rename-Item -Path $nupkgPath -NewName $zipPath
$unzippedPath = Join-Path -Path $TestDrive -ChildPath "ExtractedModule"
New-Item -Path $unzippedPath -ItemType Directory -Force
Expand-Archive -Path $zipPath -DestinationPath $unzippedPath

# Check that .gitkeep files exist in the extracted package
$extractedPublicGitkeep = Join-Path -Path $unzippedPath -ChildPath "Public\.gitkeep"
$extractedPrivateGitkeep = Join-Path -Path $unzippedPath -ChildPath "Private\.gitkeep"

Test-Path -Path $extractedPublicGitkeep | Should -Be $True
Test-Path -Path $extractedPrivateGitkeep | Should -Be $True

# Cleanup
Remove-Item -Path $unzippedPath -Recurse -Force -ErrorAction SilentlyContinue
}
}