sayedihashimi / package-web

Extensions for ASP.NET web projects package creation
32 stars 18 forks source link

PackageWeb fails to unzip when run under a Windows Service account #48

Open tbehunin opened 11 years ago

tbehunin commented 11 years ago

For some reason when Publish-Interactive.ps1 is executed as a Windows Service (e.g. automated builds, continuous integration environments, etc.), it silently fails to extract the zip - no error message is indicated anywhere as to the reason why it doesn't unzip. Everything appears to function fine, with the exception to the following method call:

$destinationFolder.CopyHere($zipPackage.Items())
sayedihashimi commented 11 years ago

Thanks for the bug report, will look into this.

kpartusch commented 10 years ago

@sayedihashimi I was experiencing this issue and found an article explaining how to use the compression library in .NET 4.5. I have done some preliminary tests using this method and it seems to work when running the build in TeamCity with a service account. I wanted to know what I needed to include in my pull request to get this change included and released.

sayedihashimi commented 10 years ago

@kpartusch thanks for the request. In general as long as your code works I'll take it in any shape.

If you're asking what I think would be ideal, then continue reading. When I created PackageWeb I was very new to PowerShell. Because of that the code isn't the prettiest and likely does some funny things.

Since then I've improved and I'd like to ensure that new code is good quality. For functions I'd like them to have

For an example of how I write PowerShell these days see one of my other repos for ex: https://github.com/ligershark/psbuild/blob/master/src/psbuild.psm1.

jmbezeau commented 7 years ago

I have made two adjustments in order to have Publish-Interactive.ps1 work with my "Release Management" definition. I call my install PowerShell with Remote PowerShell Task.

So in my main script, I added a simple Write-Host fonction, thus overriding the build-in function. function Write-Host($string) { $string }

In the Publish-Interactive.ps1, I replaced the Extract-Zip function with the following code: function Extract-Zip { param( [string]$zipfilename = $(throw "zipfilename is a required parameter for Extract-Zip"), [string]$destination = $(throw "destination is a required parameter for Extract-Zip"))

if(!(Test-Path $zipFilename)) { throw [system.IO.FileNotFoundException] ("Zipfile not found at [{0}]" -f $zipFilename)   }
if(!(Test-Path $destination)) { throw [system.IO.DirectoryNotFoundException] ("destination not found at [{0}]" -f $destination) }

# required in case there are any .. or . characters in the path
$zipFilename = (Resolve-Path $zipFilename)
$destination = (Resolve-Path $destination)

if(test-path($zipfilename))
{   
    Add-Type -Assembly 'System.IO.Compression.FileSystem'
    [System.IO.Compression.ZipFile]::ExtractToDirectory($zipfilename, $destination)
}
else{
    Write-Error ("Zipfile not found [{0}]" -f $zipFilename)
}

}