Revision Difference
Setting_up_VSCode#562951
<cat>Code.Intro</cat>
<title>Setting up Visual Studio Code</title>
<warning>Additional configuration is required for Visual Studio Code to work fully, make sure you read the entire article.</warning>
# Installation and setup
* [Download & install Visual Studio Code](https://code.visualstudio.com/)
* [Download & install .NET 7 SDK](https://dotnet.microsoft.com/download/dotnet/7.0)
* [Download & install .NET 9 SDK](https://dotnet.microsoft.com/download/dotnet/9.0)
* [Download & install C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)
⤶
<warning>⤶
S&box now uses .NET 9. Any other version will not work. If you are having issues, make the .NET 9 SDK is installed.⤶
</warning>⤶
## Enable Roslyn analyzers
You need to enable Roslyn analyzers if they are not already, without this you will get reference errors.
The simplest way is File -> Preferences -> Settings, from there search for "roslyn" and tick the setting "Enable Roslyn Analyzers".
<upload src="a5727/8d96338ca87e4b8.png" size="12823" name="image.png" />
Be sure to save your settings.
## Add a solution to the project directory
Because s&box generates a `.sln` file in the s&box app directory rather than your game project directory, VS Code will have no solution to load, and will instead load your game's `.csproj` on its own, which will prevent it from resolving references to classes from `sbox/addons/base/code/Base Library.csproj`. To fix this, configure the s&box editor to use VS rather than VS Code in `Edit -> Preferences`, generate and open the solution using `Game -> Open in Visual Studio` with your game project open in the editor, and save the solution to your project directory. You can then set your preferred code editor back to VS Code and develop as normal with fully working Intellisense.
# Opening projects
After [creating your game project](https://wiki.facepunch.com/sbox/Games/GettingStarted), you can open your addon folder in VSCode via `File -> Open Folder...`.
<upload src="a5727/8d963395a10fc3e.png" size="8076" name="image.png" />
You can also open the project directly from the S&box Editor by clicking `File -> Open Solution`.
## Adding debugger configuration
We need to add a debugging configuration to debug addons. Create the following file in your addon directory `.vscode\launch.json`:
```cs
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processName": "sbox.exe", // or sbox-dev.exe
"requireExactSource": false // makes sure you can debug stuff with codegen (e.g entities)
}
]
}
```
You can now start debugging your addons by setting breakpoints and pressing F5:
![](https://i.imgur.com/NqxzROM.gif)
Keep in mind that you need to manually start s&box first before debugging.
# Recommended extensions
[Visual Studio Keymap](https://marketplace.visualstudio.com/items?itemName=ms-vscode.vs-keybindings): Adds Visual Studio keymaps in case you are used to Visual Studio shortcuts.
[JetBrains Keymap](https://marketplace.visualstudio.com/items?itemName=isudox.vscode-jetbrains-keybindings): Adds JetBrains keymaps in case you are used to JetBrains shortcuts.
[EditorConfig for VS Code](https://marketplace.visualstudio.com/items?itemName=editorconfig.editorconfig): Automatically format your code with the s&box coding style
[SCSS Formatter](https://marketplace.visualstudio.com/items?itemName=sibiraj-s.vscode-scss-formatter): Automatically format your scss files.
[vscode-solution-explorer](https://marketplace.visualstudio.com/items?itemName=fernandoescolar.vscode-solution-explorer): Visual Studio-like solution explorer for Visual Studio Code.
[C# Snippets](https://marketplace.visualstudio.com/items?itemName=jorgeserrano.vscode-csharp-snippets): C# code snippets.
[Auto-Using for C#](https://marketplace.visualstudio.com/items?itemName=fudge.auto-using): Auto import namespaces.
[C# Extensions](https://marketplace.visualstudio.com/items?itemName=tdallau-csharpextensions.csharpextensions): Quickly create new classes and generate constructors.
[C# Namespace Autocompletion](https://marketplace.visualstudio.com/items?itemName=adrianwilczynski.namespace): IntelliSense for writing namespaces.
[C# XML Documentation Comments](https://marketplace.visualstudio.com/items?itemName=k--kato.docomment): Easier code documentation.
[GitLens](https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens): A useful extension when working with Git.