Open liamkirwan opened 5 years ago
This is why I skipped using the DscBuildHelpers and used the following code. In my case the function 'Compress-DscResourceModule' never worked.
task CompressModulesWithChecksum {
if (-not (Test-Path -Path $BuildOutput\CompressedModules)) {
mkdir -Path $BuildOutput\CompressedModules | Out-Null
}
$modules = Get-ModuleFromFolder -ModuleFolder "$ProjectPath\DscResources\"
$compressedModulesPath = "$BuildOutput\CompressedModules"
foreach ($module in $modules) {
$destinationPath = Join-Path -Path $compressedModulesPath -ChildPath "$($module.Name)_$($module.Version).zip"
Compress-Archive -Path "$($module.ModuleBase)\*" -DestinationPath $destinationPath
$hash = (Get-FileHash -Path $destinationPath).Hash
try {
$stream = New-Object -TypeName System.IO.StreamWriter("$destinationPath.checksum", $false)
[void] $stream.Write($hash)
}
finally {
if ($stream) {
$stream.Close()
}
}
}
}
And you couldn't do a PR :)
Will do later. The quick way was just to replace the function call :)
Hello, just including some more colour on this as I think it explains the issue I've been seeing. The file encoding of the checksum file is always UTF-8, so that doesn't seem to matter. But, checksum files with this extra newline refuse to match the SHA-256 of the zip file even when it's correct.
I think the underlying cause is the Get-FileHash | Set-Content - is there a reason not to use New-DscChecksum here? If not, I also found that -NoNewLine switch on Set-Content removed the issue.