# Packaging in Visual Studio Code

PowerShell Pro Tools provides an [extension for Visual Studio Code](https://marketplace.visualstudio.com/items?itemName=ironmansoftware.powershellprotools). PowerShell Pro Tools takes advantage of the package.psd1 file to configure packaging for scripts within VS Code.&#x20;

## Requirements for Packaging

* PowerShell Pro Tools Visual Studio Code Extension
* .NET Core SDK 2.0 or later

## Compiling a Script&#x20;

To compile a script into an executable, open a PS1 file. In the top right of the toolbar, you will find a Package Script as Exe button. Clicking this button will start the packaging process.&#x20;

![Package Script as Exe Button](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MMfXUs2AQpLghNUDbO8%2F-MMfYUFOXuAduy3B7kf-%2Fimage.png?alt=media\&token=1d7ebe98-db65-4571-aaf2-6b15f0e6764b)

If this is the first time you have clicked the button, a `package.psd1` file will be created in the current workspace's root. So for example, if you have the folder `C:\src\scripts` open in Visual Studio Code, the file `C:\src\scripts\package.psd1` will be created.

Next, the packaging process will start. The PowerShell Pro Tools Output Pane will be activated and will display log information about the packaging process.

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MMfXUs2AQpLghNUDbO8%2F-MMfZ4cFoDYixVgRXTOZ%2Fimage.png?alt=media\&token=ef350147-68f9-4426-915e-4fd3e841a48f)

## Configuration Packaging

To configure packaging, you can change settings within the generated `package.psd1` file. You can learn more about the syntax of the file by [clicking here](https://docs.poshtools.com/powershell-pro-tools-documentation/packaging/package.psd1).

The default configuration will look something like this.&#x20;

```
@{
    Root = 'c:\Users\adamr\Desktop\test\test\test.ps1'
    OutputPath = 'c:\Users\adamr\Desktop\test\out'
    Package = @{
        Enabled = $true
        Obfuscate = $false
        HideConsoleWindow = $false
        DotNetVersion = 'v4.6.2'
        FileVersion = '1.0.0'
        FileDescription = ''
        ProductName = ''
        ProductVersion = ''
        Copyright = ''
        RequireElevation = $false
        ApplicationIconPath = ''
        PackageType = 'Console'
    }
    Bundle = @{
        Enabled = $true
        Modules = $true
        # IgnoredModules = @()
    }
}
```

### Root Package.psd1

The root `package.psd1` file is generated at the root of the current workspace folder. Here's an example of a file structure with a root `package.psd1` file. Clicking Package Script as Exe on an script will use this `package.psd1` file.

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MMfXUs2AQpLghNUDbO8%2F-MMfZniNUT6o1WkQMK4g%2Fimage.png?alt=media\&token=ce49467b-93b7-4ad3-a583-9d9eeb414db4)

### Scoped Package.psd1&#x20;

You can also include the `package.psd1` file in a particular folder. When packaging scripts in that folder, the scoped `package.psd1` file will be used.&#x20;

Take the following folder structure for example.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MMfXUs2AQpLghNUDbO8%2F-MMf__C7Z7YnXw1bfhsf%2Fimage.png?alt=media\&token=aa5e135a-8fb4-4b1c-8eed-32da5e0d86b7)

When packaging the `test\test.ps1` file, the `test\package.psd1` will be used to package the script. When packaging the `test2\test2.ps1` file, the `test\package.psd1` file will be used. The root `package.psd1` will used when packaging `test3\test3.ps1` because that folder does not have a scoped package config file.&#x20;

### Package.psd1 template

You can set the package.psd1 template that is used to create the default package.psd1 by setting the path to the file within your settings.&#x20;

![](https://3667946160-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LNFE66tpE_51uobNA70%2F-MZER9O3yJ9Yc2FHFUyh%2F-MZERUFeKy_zbs6WhILX%2Fimage.png?alt=media\&token=a5a71b19-16ad-49be-8eab-1ef7d2d42461)

You can use two replacement variables that will be set when the file is created.&#x20;

**$root** - Replaced by the path to the PS1 file being packaged&#x20;

**$outputPath** - Path to the directory to output to.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.poshtools.com/powershell-pro-tools-documentation/visual-studio-code/packaging-in-visual-studio-code.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
