> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Bach builds Windows installers from one bach.toml with the bach command: bach init, bach check, bach preview, bach build. Installs are per user and need no administrator rights by default. installer.scope = "machine" installs for every user after one Windows prompt. On Windows, run setup files with Start-Process -Wait -PassThru in PowerShell, and give signtool arguments that start with the word sign.

# Package a .NET app

> Publish a .NET app and turn it into a Setup.exe with Bach, either self-contained or with a check that installs only where the .NET runtime is present.

This guide makes a setup file for a .NET desktop app, such as a WPF or Windows Forms program, or a console tool.

## 1. Decide about the .NET runtime

A .NET app needs the .NET runtime. You can handle that in two ways:

* **Self-contained:** the runtime is part of your build folder. Users need nothing else. The setup file gets bigger.
* **Framework-dependent:** your app is small, but the right .NET runtime must be installed on the user's computer. Bach can check for it and tell the user where to get it.

## 2. Publish

> [tab] Self-contained
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> dotnet publish -c Release -r win-x64 --self-contained true
> ```

> [tab] Framework-dependent
>
> ```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
> dotnet publish -c Release -r win-x64 --self-contained false
> ```

Either way, the result is in `bin/Release/<framework>/win-x64/publish`, for example `bin/Release/net8.0-windows/win-x64/publish`.

## 3. Create bach.toml

Run this in the folder with your `.csproj`:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach init
```

Bach reads the project file: `Product` or the assembly name, `Version`, `Company` or `Authors`, and the target framework. For a WPF app on .NET 8 you get (without the commented-out options):

```toml bach.toml theme={"theme":{"light":"github-light","dark":"github-dark"}}
[app]
name = "Paint"
version = "4.2.0"
publisher = "Your Company"
executable = "Paint.exe"

[files]
source = "bin/Release/net8.0-windows/win-x64/publish"
exclude = ["*.pdb", "*.log", "Thumbs.db", ".DS_Store"]

# `dotnet publish -c Release -r win-x64 --self-contained` puts the .NET runtime
# into your build, so users need nothing else. Only if you publish with
# `--self-contained false`, remove the "# " from the four lines below.
# [[requirements]]
# kind = "dotnet"
# version = "8.0"
# desktop = true
```

The requirement starts commented out, which is right for a self-contained publish. That's also what the [release workflow](/docs/guides/releasing.md) does. **If you publish framework-dependent, uncomment the block,** so the installer checks for the runtime.

> [!NOTE]
>
> Bach 0.11.3 and earlier wrote the block uncommented. If you publish self-contained, delete it, or the installer asks users to install a runtime your app already carries.

`desktop = true` checks for the .NET Desktop Runtime, which WPF and Windows Forms apps need. It's set when your target framework ends in `-windows`.

## 4. Check and build

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
bach check
bach preview
bach build
```

## Next steps

* [Requirements](/docs/guides/requirements.md)
* [Customize the install window](/docs/guides/customize-the-window.md)
* [Sign your setup file](/docs/guides/signing.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.