S&box Wiki

Revision Difference

Setting_up_VSCode#544790

<cat>Code.Intro</cat> <title>Setting up Visual Studio Code</title> ⤶ While s&box addon development is currently mainly targeting Visual Studio, you can still use Visual Studio Code with full support for IntelliSense and debugging too.⤶ <warning>Additional configuration is required for Visual Studio Code to work fully, make sure you read the entire article.</warning>⤶ # Installation and setup Download and install Visual Studio Code from [here](https://code.visualstudio.com/). ## Required Visual Studio Code extensions⤶ The following Visual Studio Code extensions will be required to write and debug s&box addons in Visual Studio Code:⤶ - [C#](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp)⤶ ⤶ ## Creating the workspace⤶ First, generate the solution by running your game **at least once**. ⤶ **[Please note you will have to do this every time you add an addon to your game before you are able to edit.]**⤶ ⤶ #⤶ ⤶ After that start Visual Studio Code and press `File -> Open Folder...`: ⤶ ![](https://i.imgur.com/kFKTFel.png) ⤶ Select the `sbox\addons` folder. After that go to `File -> Save Workspace As...` and save it as `addons.code-workspace` inside the addons folder.⤶ ## Enabling Roslyn analyzers⤶ The C# extension has Roslyn analyzers disabled by default. These are required for s&box code generation so that we won't get errors in auto generated code like ClientCmd and ServerCmds calls. This will also allow you to get automatic suggestions for your code.⤶ To enable Roslyn analyzers, create a file called `omnisharp.json` in your addons folder with the following content:⤶ ```cs⤶ {⤶ "RoslynExtensionsOptions": {⤶ "enableAnalyzersSupport": true⤶ }⤶ }⤶ ```⤶ ⤶ ## Adding debugger configuration⤶ We need to add a debugging configuration to debug addons. Create the following file in `addons\.vscode\launch.json`:⤶ ## Install C# extension⤶ ⤶ You will require the [C# Extension](https://marketplace.visualstudio.com/items?itemName=ms-dotnettools.csharp) in order to work properly with C# in VSCode, simply download this and make sure to reload VSCode.⤶ ⤶ ### Enabling Roslyn analyzers⤶ ⤶ It is incredibly important to enable Roslyn analyzers, you will get errors on generated code if you do not enable them.⤶ 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.⤶ ⤶ # Opening projects⤶ ⤶ After [creating your addon folder structure](https://wiki.facepunch.com/sbox/Making_Gamemode) and running your game to generate the .csproj files you can open your addon folder in VSCode via `File -> Open Folder...`. ⤶ <upload src="a5727/8d963395a10fc3e.png" size="8076" name="image.png" />⤶ ## 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", "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. # Themes Visual Studio Code has first-class support for themes. You can browse and install themes from [here](https://vscodethemes.com/).