question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reference module with Functions-specific command declarations

See original GitHub issue

When authoring PowerShell functions, the Functions-specific commands (such as Push-OutputBinding, Invoke-ActivityFunction, etc.) are difficult to discover. The user must find the names and invocation syntax in the documentation and type them in correctly. These commands cannot be discovered interactively via the regular PowerShell means (Get-Help, Get-Command), and VSCode cannot help with autocomplete, IntelliSense, etc., which complicates functions authoring.

These commands are defined in an internal module that is automatically loaded by the worker during function execution. However, this module cannot be imported into a standalone PowerShell session because of the dependency on worker’s internals.

What we can do is provide a special reference module containing all the commands with parameters and help text, with a “do-nothing” implementation. We will update this module on adding or changing commands, and we will distribute it together with the PowerShell worker (so it always stays in sync with the actual implementation).

Challenge: it would be great if we could make sure this module automatically loaded when Functions are authored in VSCode. At the same time, we don’t want this module to be loaded into the sessions used for executing Functions code, so including this module into the global PSModulePath is probably not a good idea. In the worst case, we can document manual steps, and this will be an improvement comparing to the current situation, but can we find a better way?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
JustinGrotecommented, Nov 30, 2021

where can you get that module?

It’s buried in the azure functions core tools. I imported it here, you can find it relative to the azure-functions-core-tools part of the path. ipmo "C:\Users\JGrote\scoop\apps\nodejs-lts\current\bin\node_modules\azure-functions-core-tools\bin\workers\powershell\7\Microsoft.Azure.Functions.PowerShellWorker.dll"

0reactions
PalmEmanuelcommented, Mar 21, 2023

An expanded workaround to get intellisense when developing Azure Functions is to first import the DLL, and then the manifest to also get the script module functions. I wrote a one-liner to find it based on the location of the function core tools (command func).

# Find and import PowerShellWorker 7.2 module, first import compiled dll module, then the manifest file
Get-ChildItem "$(Split-Path (Get-Command 'func').Source -Parent)\*\7.2" -Recurse |
    Get-ChildItem -Recurse -Filter 'Microsoft.Azure.Functions.PowerShellWorker*' -File |
    Where-Object { $_.Extension -in '.dll','.psd1' } |
    Import-Module
Read more comments on GitHub >

github_iconTop Results From Across the Web

6. Modules — Python 3.11.4 documentation
A module can contain executable statements as well as function definitions. These statements are intended to initialize the module. They are executed only...
Read more >
What are and How to Import Modules in Python?
import statement allows you to import specific functions/variables from a module instead of importing everything. In the previous example, when you imported ...
Read more >
Import-Module (Microsoft.PowerShell.Core)
Specifies an array of assembly objects. This cmdlet imports the cmdlets and providers implemented in the specified assembly objects. Enter a variable that ......
Read more >
TypeScript: Documentation - Modules
Any declaration (such as a variable, function, class, type alias, or interface) can be exported by adding the export keyword. StringValidator.ts. ts. export ......
Read more >
Get-Command - Module: Microsoft.PowerShell.Core
Specifies an array of command nouns. This cmdlet gets commands, which include cmdlets, functions, and aliases, that have names that include the specified...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found