1

I do a lot of Winforms and WPF GUI design in Visual Studio and then further perfect my form in Visual Studio Code. (I'm using PowerShell Pro Tools from Ironman Studios)

In VSCode, it's extremely easy to add and use snippets for PowerShell, especially with the Snippet Generator and Snippets Viewer addons installed:

VSCode Snippets Manager

I'm trying to replicate this somehow in Visual Studio Community 2022. I've defined a PowerShell snippet with the following code:

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>GUI Enable Visual Styles</Title>
            <Description>Enable Visual Styles</Description>
            <Shortcut>enablevs</Shortcut>
        </Header>
        <Snippet>
            <Code Language="PowerShell">
                <![CDATA[
                Add-Type -AssemblyName System.Windows.Forms
                Add-Type -AssemblyName System.Drawing
                Add-Type -AssemblyName PresentationCore,PresentationFramework
                [System.Windows.Forms.Application]::EnableVisualStyles()
                ]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

And I saved the file here: C:\Users\Username\Documents\Visual Studio 2022\Code Snippets\PowerShell\My Code Snippets\EnableVisualStyles.snippet

Then, with a PowerShell file open, I right click and choose Snippet > Insert Snippet:

Insert Snippet

But I get an empty input box shown here:

Snippet Input

No matter what I type in that box, for example the shortcut name of the snippet, I get no suggestions and if I press enter I get the following error:

Error

Am I missing something? Is there any way to access PowerShell snippets in.ps1 files?

Is there some kind of extension on the marketplace that will add extended support for snippets?

This is pretty crucial to me, as I depend heavily on my snippets library when developing.

Any help at all would be extremely welcomed.

1 Answer 1

1

I too ran into this problem with Visual Studio 2022 Community Edition. Based on my experience with VS2022, it leaves too much to be desired.

You could try Downloading and Installing "PowerShell Tools for Visual Studio 2022" from the Visual Studio Marketplace (assuming you haven't done so already).

PowerShell Tools for Visual Studio 2022: https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsVS2022

Even after installing the PowerShell Tools, I kept running into problems, as it seems Microsoft has gutted the majority of the PowerShell Assets, especially in relation to WPF and the like.

Personally, I got tired of playing around with "Visual Studio 2022", which I ultimately Uninstalled and instead, Installed "Visual Studio 2019" in it's place.

Visual Studio 2019 Downloads: https://learn.microsoft.com/en-us/visualstudio/releases/2019/release-notes

Much like VS2022, the "PowerShell Tools for Visual Studio" extension, that is compatible with VS2017 and VS2019 needs to be Installed.

PowerShell Tools for Visual Studio (VS2017 & VS2019): https://marketplace.visualstudio.com/items?itemName=AdamRDriscoll.PowerShellToolsforVisualStudio2017-18561

The major difference, between the VS2019 Version, is that the PowerShell Assets and Resources (including WPF, Forms, Scripting, Module, etc.) are still available.

I did do some research into the PowerShell Snippets and it seems that they are specific to "Visual Studio Code" only.

PowerShell (Visual Studio Code): https://marketplace.visualstudio.com/items?itemName=ms-vscode.PowerShell

You could also look into "PowerShell Pro Tools" for Visual Studio, if you can afford to purchase a commercial extension.

PowerShell Pro Tools: https://ironmansoftware.com/powershell-pro-tools

That is all I have for now. I hope this info helps you out. If I run into any other Information, that may be beneficial to you, I'll be sure to post an Update.

Sign up to request clarification or add additional context in comments.

1 Comment

I apologize for leaving so many Links. If there was any way to point you in the right direction, without them, I definitely would have gone that route.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.