The "PowerShellPackageTask" task failed unexpectedly.

Issue #182 new
Adam Birds created an issue

Keep getting this error when trying to debug. Tried running as admin too. I do have permissions to that folder. On latest version

Severity Code Description Project File Line Suppression State
Error The "PowerShellPackageTask" task failed unexpectedly.
System.UnauthorizedAccessException: Access to the path 'C:\Users\adam.birds\AppData\Local\Temp\User-Deletion-Tool.ps1' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at PowerShellToolsPro.Packager.BundleStage.WriteText(String path, String text)
at PowerShellToolsPro.Packager.BundleStage.Execute(PackageProcess process, StageResult previousStage)
at PowerShellToolsPro.Packager.PackageProcess.Execute()
at PowerShellToolsPro.MsBuild.PowerShellPackageTask.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() User-Deletion-Tool C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.targets 5

Comments (11)

  1. Adam Birds reporter

    This seems to appear once I add the below code to the script.

    Function Get-UserToDelete {
        #[System.Reflection.Assembly]::LoadFrom(“$PSScriptRoot\..\Helpers\CubicOrange.Windows.Forms.ActiveDirectory.dll”) | Out-Null
        Add-Type -Path (Join-Path -Path (Split-Path $Script:MyInvocation.MyCommand.Path) -ChildPath '..\Helpers\CubicOrange.Windows.Forms.ActiveDirectory.dll')
        $DialogPicker = New-Object CubicOrange.Windows.Forms.ActiveDirectory.DirectoryObjectPickerDialog
        $DialogPicker.AllowedLocations = [CubicOrange.Windows.Forms.ActiveDirectory.Locations]::JoinedDomain
        $DialogPicker.AllowedObjectTypes = [CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes]::Users
        $DialogPicker.DefaultLocations = [CubicOrange.Windows.Forms.ActiveDirectory.Locations]::JoinedDomain
        $DialogPicker.DefaultObjectTypes = [CubicOrange.Windows.Forms.ActiveDirectory.ObjectTypes]::Users
        $DialogPicker.ShowAdvancedView = $false
        $DialogPicker.MultiSelect = $false
        $DialogPicker.TargetComputer = $FullDomainName
        $DialogPicker.SkipDomainControllerCheck = $false
        $DialogPicker.Providers = [CubicOrange.Windows.Forms.ActiveDirectory.ADsPathsProviders]::Default
        $DialogPicker.AttributesToFetch.Add('distinguishedName')
        $DialogPicker.ShowDialog()
        Return $DialogPicker.SelectedObjects
    }
    

  2. Adam Birds reporter

    Also to add, tested this with both VS 2017 and VS 2019.
    Also ensured I updated the PowerShell Tools to latest as was a few back, but same on both.

    I have tested with bundle ticked as well, but this didn’t resolve, these are also the exact same packaging settings I use with another solution I have which contains the exact same code.

  3. Adam Birds reporter

    I have also tested with both of below lines to load the DLL file but the same with each:

    [System.Reflection.Assembly]::LoadFrom($PSScriptRoot\..\Helpers\CubicOrange.Windows.Forms.ActiveDirectory.dll) | Out-Null
    

    Add-Type -Path (Join-Path -Path (Split-Path $Script:MyInvocation.MyCommand.Path) -ChildPath '..\Helpers\CubicOrange.Windows.Forms.ActiveDirectory.dll')
    

  4. Adam Birds reporter

    I have even tried using one of my old solutions and editing it so it matches my new one and I get the same issue.

  5. Adam Birds reporter

    Excellent, thanks, let me know if you want me to email you a zip of my solution to test with. Thanks

  6. Adam Driscoll

    The method that is being called is no longer used in the current code base. It looks to me like there may be an installation issue. Can you please attach the file that you have in :C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\PowerShell Tools for Visual Studio\PowerShellProTools.Packager.dll?

  7. Adam Driscoll

    Hmmm ok. After looking at this again it does look like the correct version is getting installed.

    I have a hunch that ASMI may be causing a problem here due to how assemblies are currently bundled with PoshTools. Can you try adding an exclusion to defender to the temp directory?

    The problem here is that the bundler is storing the assembly as a Base64 string in the PS1 which is causing it to trigger ASMI. I can change how this is packaged so this won’t happen but would like to validate that this is the case first.

    I’m not seeing defender trigger on my machine so that’s why it’s just a hunch.

  8. Ian Morrish

    I’m getting similar (and random) problems using VS, VSCode or the PS module with any script that has DLL’s as import-module or add-type.

    Turning off AIP mad things slightly better (can create exe but still without packaging (I use a . sourced file to load the DLL’s outside the exe.

    All seems to have happend since adding .net core 3.0 and/or some windows 10 update and our corporate intune license.

    Happens on 2 machines that used to compile these scripts fine just 2 months ago.

  9. Log in to comment