The "PowerShellPackageTask" task failed unexpectedly.
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)
-
reporter -
Can you share your packaging settings?
-
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.
-
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')
-
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.
-
Ok. Thanks for all the info. Looking into this today.
-
reporter Excellent, thanks, let me know if you want me to email you a zip of my solution to test with. Thanks
-
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?
-
reporter 2017:
2019:
Issue occurs on both versions so attached it twice.
-
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.
-
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.
- Log in to comment
This seems to appear once I add the below code to the script.