vscode-azurefunctions icon indicating copy to clipboard operation
vscode-azurefunctions copied to clipboard

V3 Functions project fails to launch with debugger because of PowerShell execution policy

Open kprpg opened this issue 5 years ago • 6 comments

Repro steps:

  1. On a brand new Azure VM, which comes pre-installed with VS2019, VS Code etc.,. Create a durableFunction using v3, and launch debugger.
  2. You will see the below error on the Console output Window of VS Code. Executing task: func host start <

func : File C:\Users\gpillai\AppData\Roaming\npm\func.ps1 cannot be loaded. The file C:\Users\gpillai\AppData\Roaming\npm\func.ps1 is not digitally signed. You cannot run this script on the current system. For more information about running scripts and setting execution policy, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:1

  • func host start
  •   + CategoryInfo          : SecurityError: (:) [], PSSecurityException
      + FullyQualifiedErrorId : UnauthorizedAccess
    

The terminal process terminated with exit code: 1

Action: azureFunctions.pickProcess Error type: Error Error Message: Failed to start debugging. Task "host start" failed with exit code "1".

Version: 0.20.0 OS: win32 Product: Visual Studio Code Product Version: 1.40.0 Language: en

Call Stack
extension.bundle.js:353:75642extension.bundle.js:353:75642
l.fire extensionHostProcess.js:47:207
m.$onDidEndTaskProcess extensionHostProcess.js:695:468

kprpg avatar Nov 13 '19 14:11 kprpg

@ankitkumarr @ahmelsayed @soninaren any ideas on this one? Is there some PowerShell script that isn't getting signed for v3?

ejizba avatar Nov 13 '19 19:11 ejizba

hmm, I don't think there is anything special to v3 here. @kprpg does this work with npm installed v2?

ahmelsayed avatar Nov 13 '19 20:11 ahmelsayed

@ahmelsayed -- we just had someone hit this during OGF run. Did we ever get to the bottom of this? What is func.ps1 -- is that something for VS Code?

brettsam avatar Dec 09 '19 14:12 brettsam

I have just hit this too. Brand new Windows 10 machine, with Visual Studio Code installed and only Azure Functions v3 installed. Following these steps https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local#create-func

using npm install -g azure-functions-core-tools@3

Visual Studio Code version info

Version: 1.41.1 (user setup)
Commit: 26076a4de974ead31f97692a0d32f90d735645c0
Date: 2019-12-18T14:58:56.166Z
Electron: 6.1.5
Chrome: 76.0.3809.146
Node.js: 12.4.0
V8: 7.6.303.31-electron.0
OS: Windows_NT x64 10.0.18363

If I then run npm install -g azure-functions-core-tools and in the project that I created when v3 was installed run func new it doesn't get that error anymore...

Actually, I was using the Terminal directly in Visual Studio Code and this error still shows. If I do this in the Windows 10 Terminal, I do not see this error.

Obviously this means that if I try debug and run in Visual Studio Code. This error prevents me from starting the host.

Running this in the Visual Studio Code terminal shows execution policies were not set up.

PS C:\> Get-ExecutionPolicy -List

        Scope ExecutionPolicy
        ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       Undefined
 LocalMachine       AllSigned

To get this to work. I had to run PowerShell as an Administrator and run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned. More is documented here on this https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6#managing-the-execution-policy-with-powershell .

jthake avatar Dec 20 '19 17:12 jthake

Filed https://github.com/Azure/azure-functions-core-tools/issues/1821 to track this on the core tools side

ejizba avatar Feb 12 '20 20:02 ejizba

I started running into this issue after installing the latest VS Code update:

Version: 1.60.0 (user setup)
Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
Date: 2021-09-01T10:41:52.311Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

Fixed it by running the following in PowerShell NOT as an Administrator Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

hhubik avatar Sep 06 '21 04:09 hhubik

I started running into this issue after installing the latest VS Code update:

Version: 1.60.0 (user setup)
Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
Date: 2021-09-01T10:41:52.311Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Windows_NT x64 10.0.19043

Fixed it by running the following in PowerShell NOT as an Administrator Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Perfect Solution, Thank you Dear

AzeemQ8 avatar Feb 21 '23 17:02 AzeemQ8