|
| 1 | +--- |
| 2 | +title: Setting up your development environment for VSCode |
| 3 | +description: A step-by-step guide for setting up your development environment using VSCode |
| 4 | +--- |
| 5 | + |
| 6 | +# Setting up your development environment for VSCode |
| 7 | + |
| 8 | +This is a guide on setting up your development environment for creating games with MonoGame using Visual Studio Code. By following this guide, you will learn how to install the necessary .NET SDK for developing C# applications, set up MonoGame C# templates for new projects, and configure Visual Studio Code with recommended extensions for C# development. By the end, you'll be fully equipped to start creating games with MonoGame using Visual Studio code. |
| 9 | + |
| 10 | +> [!NOTE] |
| 11 | +> The only development environment that MonoGame officially supports on Linux is [Visual Studio Code](https://code.visualstudio.com/). |
| 12 | +> |
| 13 | +> [Visual Studio for Mac will be discontinued](https://devblogs.microsoft.com/visualstudio/visual-studio-for-mac-retirement-announcement/) by Microsoft in August 2024. At that time, [Visual Studio Code](https://code.visualstudio.com/) will be the only development environment supported by MonoGame on macOS. |
| 14 | +
|
| 15 | +## Install .NET 8 SDK |
| 16 | +To develop with C#, you will need to install the .NET SDK. At the time of this writing, the current version is .NET 8.0. You can follow the instructions below based your operating system to install the .NET 8.0 SDK |
| 17 | + |
| 18 | +> [!NOTE] |
| 19 | +> The current version of MonoGame (3.8.1.303) targets .NET 6.0. Regardless you can, and it is recommended to, use .NET 8.0. The only requirement for having .NET 6.0 installed is if you are developing extensions for the MGCB Editor. |
| 20 | +
|
| 21 | +# [Windows](#tab/windows) |
| 22 | +1. Navigate to [https://dotnet.microsoft.com/en-us/download](https://dotnet.microsoft.com/en-us/download) |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +2. Click the **.NET SDK x64** download button to download. This will take you to the download page where the **dotnet-sdk-8.x.yyy-win-x64.exe** will download. |
| 27 | +3. When the download completes, run the **dotnet-sdk-8.x.yyy-win-x64.exe** installer and complete the steps to install .NET on your machine. |
| 28 | +4. When the install completes, open a new **Command Prompt** window and run the command `dotnet` to verify the installation was successful. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +# [macOS](#tab/macos) |
| 33 | +1. Navigate to [https://dotnet.microsoft.com/en-us/download](https://dotnet.microsoft.com/en-us/download) |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +2. Download the .NET SDK x64-(Intel) Installer |
| 38 | + |
| 39 | +> [!NOTE] |
| 40 | +> For the time being, MonoGame requires that you install the **.NET SDK x64-(Intel)** version of the .NET SDK even if you are running on an Apple Silicon (M1/M2) Mac. For Apple Silicon Macs, it also requires that [Rosetta](https://support.apple.com/en-us/HT211861) is enabled. |
| 41 | +
|
| 42 | +3. Once the installation **.pkg** file finishes downloading, run it and follow the prompts to install the .NET SDK |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | +4. Once the installation is complete, open a new terminal window and run the command `dotnet` to verify the installation was successful. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | +# [Linux](#tab/linux) |
| 51 | +1. Open a new **Terminal** window. |
| 52 | +2. Enter the following command in the terminal to download the **dotnet-install.sh** |
| 53 | + |
| 54 | +```sh |
| 55 | +wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh |
| 56 | +``` |
| 57 | + |
| 58 | +3. Grant permission for the script to execute by entering the following command in the terminal: |
| 59 | + |
| 60 | +```sh |
| 61 | +chmod +x ./dotnet-install.sh |
| 62 | +``` |
| 63 | + |
| 64 | +4. Run the script to install the .NET 8 SDK by entering the following command in the terminal: |
| 65 | + |
| 66 | +```sh |
| 67 | +./dotnet-install.sh |
| 68 | +``` |
| 69 | + |
| 70 | + |
| 71 | + |
| 72 | +5. You will now need to setup your environment variables so that the `dotnet` command is recognized. To do this, open the file `~/.bashrc` in a text editor and add the following lines to the end of the file. |
| 73 | + |
| 74 | +```sh |
| 75 | +export DOTNET_ROOT=$HOME/.dotnet |
| 76 | +export PATH=$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools |
| 77 | +``` |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | +6. Save and close the file, close any open terminal windows, then open a new terminal window so the new environment variables are registered. |
| 82 | +7. Enter the `dotnet` command to validate that the .NET 8 SDK is now installed. |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +> [!TIP] |
| 89 | +> If you intend to target mobile platforms, you will also need to install the corresponding workloads. Enter the following commands in a command prompt/terminal |
| 90 | +> |
| 91 | +> ```sh |
| 92 | +> dotnet workload install ios |
| 93 | +> dotnet workload install android |
| 94 | +> ``` |
| 95 | +
|
| 96 | +## Install MonoGame Templates |
| 97 | +The .NET SDK installation provides the default C# project templates but does not include the MonoGame templates. These templates must be installed manually. |
| 98 | +
|
| 99 | +1. Open a new terminal window (**Command Prompt** on Windows). |
| 100 | +
|
| 101 | +```sh |
| 102 | +dotnet new install MonoGame.Templates.CSharp |
| 103 | +``` |
| 104 | +
|
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +> [!NOTE] |
| 109 | +> When installing the templates, an error message may appear regarding the UWP template failing to install. This error can be safely ignored, as the UWP templates are deprecated and will be removed in a future MonoGame release. |
| 110 | +
|
| 111 | +## Install Visual Studio Code |
| 112 | + |
| 113 | +# [Windows](#tab/windows) |
| 114 | +1. Open your web browser and navigate to [https://code.visualstudio.com/](https://code.visualstudio.com/). |
| 115 | + |
| 116 | + |
| 117 | + |
| 118 | +2. Click the **Download for Windows** button. This will redirect you to the download page where the installer will automatically download. |
| 119 | +3. When the download completes, run the installer and complete the steps to install Visual Studio Code. |
| 120 | + |
| 121 | +# [macOS](#tab/macos) |
| 122 | +1. Open your web browser and navigate to [https://code.visualstudio.com/](https://code.visualstudio.com/). |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +2. Click the **Download Mac Universal** button. This will redirect you to the page where the application archive (.zip) file will begin downloading. |
| 127 | +3. Extract the contents of the VSCode archive that downloaded by double-clicking it inside a Finder window. This will extract the **Visual Studio Code.app** file. |
| 128 | +4. Drag the **Visual Studio Code.app** file into the **Applications** folder, making it available in the macOS Launchpad. |
| 129 | + |
| 130 | +# [Linux](#tab/linux) |
| 131 | +The recommended method for installing Visual Studio Code in Linux is to use Snap. This is supported by most Linux distributions. |
| 132 | + |
| 133 | +- [Snap Package](https://code.visualstudio.com/docs/setup/linux#_snap) |
| 134 | + |
| 135 | +There are also individual guides below based on your Linux distribution if you do not want to use Snap: |
| 136 | + |
| 137 | +- [Debian and Ubuntu base distributions](https://code.visualstudio.com/docs/setup/linux#_debian-and-ubuntu-based-distributions) |
| 138 | +- [RHEL, Fedora, and CentOS based distributions](https://code.visualstudio.com/docs/setup/linux#_rhel-fedora-and-centos-based-distributions) |
| 139 | +- [openSUSE and SLE-based distributions](https://code.visualstudio.com/docs/setup/linux#_opensuse-and-slebased-distributions) |
| 140 | +- [AUR package for Arch Linux](https://code.visualstudio.com/docs/setup/linux#_aur-package-for-arch-linux) |
| 141 | +- [Installing .rpm package manually](https://code.visualstudio.com/docs/setup/linux#_installing-rpm-package-manually) |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Install Visual Studio Code C# Extensions |
| 146 | +To transform Visual Studio Code from a simple text editor into a powerful development environment for C# projects, you must install the Visual Studio Code C# extension. This extension enhances the editor by providing syntax highlighting, code analysis, IntelliSense, and other features that significantly improve the development experience and productivity when working with C#. |
| 147 | + |
| 148 | +1. Open Visual Studio Code. |
| 149 | +2. Click the **Extensions** icon in the **Activity Bar** on the left. |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | +3. In the **Search Box** type `C#`. |
| 154 | +4. Click **Install** for the **C# Dev Kit** extension. Installing this will also install the base **C#** extension. |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | +--- |
| 159 | + |
| 160 | +## Setup Wine For Effect Compilation - MacOS/Linux Only |
| 161 | +Effect (shader) compilation requires access to DirectX. This means it will not work natively on macOS and Linux systems, but it can be used through [Wine](https://www.winehq.org/). |
| 162 | + |
| 163 | +# [Windows](#tab/windows) |
| 164 | +> [!NOTE] |
| 165 | +> Windows users do not require an additional setup for effect compilation and can skip this section. |
| 166 | +
|
| 167 | +# [macOS](#tab/macos) |
| 168 | +MonoGame |
| 169 | +MonoGame provides a setup script that can be executed to setup the Wine environment for Effect (shader) compilation. However, this script has the following prerequisites that must first be setup |
| 170 | +- **curl** must be installed |
| 171 | +- **p7zip** must be installed |
| 172 | +- **wine-stable** must be installed. |
| 173 | + |
| 174 | +These can be installed using **brew**. |
| 175 | + |
| 176 | +1. Open a terminal window. |
| 177 | +2. Enter the following command: |
| 178 | + |
| 179 | +```sh |
| 180 | +brew install p7zip curl |
| 181 | +brew install --cask wine-stable |
| 182 | +``` |
| 183 | + |
| 184 | +> [!CAUTION] |
| 185 | +> It is recommended that you use `wine-stable` and not `wine-staging`. |
| 186 | +
|
| 187 | +3. Now that the prerequisites are installed, download the [mgfxc_wine_setup.sh](https://monogame.net/downloads/net6_mgfxc_wine_setup.sh) script and execute it by entering the following command in the terminal: |
| 188 | + |
| 189 | +```sh |
| 190 | +wget -qO- https://monogame.net/downloads/net6_mgfxc_wine_setup.sh | bash |
| 191 | +``` |
| 192 | + |
| 193 | +This will create new directory called `.winemonogame` in your home directory. If you ever wish to undo the setup this script performed, just simply delete that directory. |
| 194 | + |
| 195 | +# [Linux](#tab/linux) |
| 196 | +MonoGame provides a setup script that can be executed to setup the Wine environment for Effect (shader) compilation. However, this script has the following prerequisites that must first be setup |
| 197 | +- **curl** must be installed |
| 198 | +- **p7zip** must be installed |
| 199 | +- **wine64** must be installed. |
| 200 | + |
| 201 | +For Debian-based distributions like Ubuntu, you can perform the following: |
| 202 | + |
| 203 | +1. Open a terminal window |
| 204 | +2. Enter the following command |
| 205 | + |
| 206 | +```sh |
| 207 | +sudo apt install curl p7zip-full wine64 |
| 208 | +``` |
| 209 | + |
| 210 | +> [!TIP] |
| 211 | +> If you receive an error stating that either of the packages do not have an install candidate, you may need to enable the universe apt repository. To do this, enter the following commands in the terminal |
| 212 | +> |
| 213 | +> ```sh |
| 214 | +> sudo add-apt-repository universe |
| 215 | +> sudo apt update |
| 216 | +> ``` |
| 217 | +> |
| 218 | +> Then try installing the packages again. |
| 219 | +
|
| 220 | +> [!CAUTION] |
| 221 | +> If you plan to install Wine using the `winehq-*` package instead, it is recommended that you use the `winehq-stable` package and not `-staging`. |
| 222 | +
|
| 223 | +3. Now that the prerequisites are installed, download the [mgfxc_wine_setup.sh](https://monogame.net/downloads/net6_mgfxc_wine_setup.sh) script and execute it by entering the following command in the terminal: |
| 224 | +
|
| 225 | +```sh |
| 226 | +wget -qO- https://monogame.net/downloads/net6_mgfxc_wine_setup.sh | bash |
| 227 | +``` |
| 228 | +
|
| 229 | +This will create new directory called `.winemonogame` in your home directory. If you ever wish to undo the setup this script performed, just simply delete that directory. |
| 230 | + |
| 231 | + |
| 232 | +--- |
| 233 | + |
| 234 | +## Apple Silicon Known Issues |
| 235 | +There is currently a two known issue when building content on an Apple Silicon (M1/M2) Mac: |
| 236 | + |
| 237 | +1. **Building Textures**: An exception occurs stating that the **freeimage** lib could not be found. |
| 238 | +2. **Building SpriteFonts**: An exception occurs stating that the **freetype** lib could not be found. |
| 239 | +3. **Building Models**: An exception occurs starting that the **assimp** lib could not be found. |
| 240 | + |
| 241 | +These issue occur due to needing compiled versions of these libs for the M1/M2 architecture. [There is currently work being done to resolve this](https://github.com/MonoGame/MonoGame/issues/8124), however in the meantime you can use the following workaround that has been provided by community members. |
| 242 | + |
| 243 | +1. Download and install the x64 version of [.NET 6](https://dotnet.microsoft.com/en-us/download/dotnet/6.0). This will place an x64 version of .NET 6 in a `/usr/local/share/dotnet/x64` directory. |
| 244 | +NOTE: It MUST be the x64 version in order for this to work. This will allow the x64 native libraries that the MonoGame Content Pipeline uses to function on the Apple Silicon device. |
| 245 | +Currently it also needs to be .NET 6 for the 3.8.1 Release of MonoGame. |
| 246 | + |
| 247 | +2. Open your .csproj and add the following lines to the first `<PropertyGroup>` section. |
| 248 | + |
| 249 | +```xml |
| 250 | +<DotnetCommand>/usr/local/share/dotnet/x64/dotnet</DotnetCommand> |
| 251 | +``` |
| 252 | + |
| 253 | +3. (Alternative) The directory above is not in the path. But we do not want the system to be confused on which .NET is should be using. So rather thatn putting the x64 verison in the path we should instead create a symlink named `dotnet64`. |
| 254 | + |
| 255 | +```sh |
| 256 | +sudo ln -s /usr/local/share/dotnet/x64/dotnet /usr/local/share/dotnet/dotnet64 |
| 257 | +``` |
| 258 | + |
| 259 | +We can then use this value as the value for `DotnetCommand` |
| 260 | + |
| 261 | +```xml |
| 262 | +<DotnetCommand>dotnet64</DotnetCommand> |
| 263 | +``` |
| 264 | + |
| 265 | +## Conclusion |
| 266 | +By following this guide, you have successfully set up your development environment for game development with MonoGame using Visual Studio Code. You've installed the .NET SDK, added MonoGame project templates, and configured Visual Studio Code with the necessary C# extensions. Now, you're ready to start creating your games! [Continue to the next section to create your first project and begin development](2_creating_a_new_project_netcore.md). |
0 commit comments