Modding:IDE reference

Index

This page is a quick reference for how to use Visual Studio 2017 or MonoDevelop/Visual Studio for Mac when creating or editing a SMAPI mod. See Modding:Modder Guide for the main guide.

Before you start

  • You should install Visual Studio Community (Windows), MonoDevelop (Linux), or Visual Studio for Mac (Mac).
  • Reviewing C# Fundamentals for Absolute Beginners is strongly recommended if you're new to programming C#.
  • Here are some basic terms to remember:
    term definition
    IDE The program used to edit, run, and compile your code (short for Integrated Development Environment). The main IDEs are Visual Studio on Windows, and MonoDevelop/Visual Studio for Mac on Linux/Mac.
    DLL The file with a .dll extension which contains your compiled code (short for Dynamic Link Library). This is the file that SMAPI reads when loading your mod.
    project A collection of source code + configuration + resources (like images) you edit in the IDE. Each project is compiled into its own DLL.
    solution A collection of projects with some global settings. The solution itself isn't compiled, but it enables some convenient features (like letting projects easily reference each other).

Create a mod project

Before you can write your mod code, you need to create a solution and project to contain it.

Windows (Visual Studio 2019/2022)

  1. Open Visual Studio 2019/2022.
  2. Click Create a new project from the start screen.
     
  3. Filter by "C#" and "Library", then choose Class Library and click Next. Make sure you don't choose Class Library (.NET Framework) which won't work.
     
  4. In the configure your new project window:
    1. Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere").
    2. Make sure "Place solution and project in the same directory" is not checked.
    3. Click "Create" to to create the project.
     
  5. Next, select NET 6.0 and click "Create" to create the project. For VS 2022, this will be on the next page.
     

Linux (MonoDevelop)

  1. Open MonoDevelop.
  2. Click File » New Solution from the menu bar:
     
  3. In the 'New Project' window, choose .NET » Library and click Next:
     
  4. Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):
     
  5. Make sure "create a project directory within the solution directory" is checked, and click Create:
     

MacOS (Visual Studio 2019 for Mac)

  1. Install the .NET 5.0 SDK if you haven't already (link: [1]).
     
  2. Open Visual Studio for Mac.
  3. Click File » New Solution from the menu bar:
     
  4. Select the correct type of class library:
     
  5. Set it to target .NET 5.0.:
     
  6. Enter a descriptive mod name for the project. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):
     

MacOS (Visual Studio for Mac)

  1. Open Visual Studio for Mac.
  2. Click File » New Solution from the menu bar:
     
  3. In the 'New Project' window, choose .NET » Library and click Next:
     
  4. Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):
     
  5. Make sure "create a project directory within the solution directory" is checked, and click Create:
     

Set the target framework

The 'target framework' is the version of .NET your code uses, which affects the version needed to run your mod. The recommended target framework is .NET 5.0, which is the version SMAPI itself targets. Please find the subsection below for your OS (Windows/Mac). You cannot use .NET 6.0.

(yes, we know .NET 5.0 is past EOL.)

In Windows Visual Studio 2019/2022

NOTE: Visual Studio 2017 MAY no longer be compatible with creating mods! If you followed Modding:Modder_Guide/Get_Started and receive errors, from the code that page instructed be copy and pasted, with regards to helper. Events in the Entry(IModhelper helper) method and ButtonPressedEventArgs from the Entry(IModHelper helper) method, try the project-creation and code-copy/paste process again with Visual Studio 2019/2022 instead.


  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer, right-click on the project and choose Properties:
     
  3. On the Application tab, change the Target Framework dropdown to .NET 5.0:
     
  4. A dialogue may appear asking you to confirm the change. Click 'Yes' to confirm:
     

In Visual Studio 2019 for Mac

If you followed the instructions above to set up your project, your framework should already be set to .NET 5.0. However, if you picked the wrong class library or you just want to check, you can follow these steps to look at the .csproj file, which is basically equivalent to setting it manually. (If you're checking that it worked, don't replace the .csproj, just check it refers to .NET 5.0.)

Unfortunately there doesn't appear to be a way to change the target framework using the GUI. However, it is very easy to follow the 1.5.5 migration guide steps:

  1. Open the .csproj file for editing:
     
  2. Replace your mod's .csproj file with this (where EXAMLE_MOD_NAME is your solution's name):
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <AssemblyName>EXAMPLE_MOD_NAME</AssemblyName>
    <RootNamespace>EXAMPLE_MOD_NAME</RootNamespace>
    <Version>1.0.0</Version>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
  </ItemGroup>
</Project>
  1. If the mod uses Harmony, add <EnableHarmony>true</EnableHarmony> to the property group.

In MonoDevelop/Visual Studio for Mac

This section is out of date for Stardew Valley 1.5.5. It appears you cannot change the .NET framework in this way with Visual Studio 2019 and Stardew Valley 1.5.5.

  1. Open the Solution pad. If it's not visible, click View » Pads » Solution from the menu:
     
  2. From the Solution pad, right-click on the project and choose Options:
     
  3. On the Build » General tab, change the Target Framework dropdown to Mono / .NET 4.5:
     

Add a file

In Visual Studio 2017

  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer pane, right-click on the project and choose Add » New Item:
     
  3. From the 'Add New Item' window, choose the file type (usually Visual C# Item » Class):
     
  4. Enter a descriptive file name and click Add:
     

In MonoDevelop/Visual Studio for Mac

  1. Open the Solution pad. If it's not visible, click View » Pads » Solution from the menu:
     
  2. From the Solution pad, right-click on the project to delete and choose Add » New File:
     
  3. From the 'New File' window, choose the file type (usually General » Empty Class):
     
  4. Enter a descriptive file name and click New:
     

Delete a file

In Visual Studio 2017

  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer pane, right-click on the file to delete and choose Delete:
     

In MonoDevelop/Visual Studio for Mac

  1. Open the Solution pad. If it's not visible, click View » Pads » Solution from the menu:
     
  2. From the Solution pad, right-click on the file to delete and choose Remove:
     

Add a NuGet package

In Visual Studio 2019/2022

  1. Click Tools » NuGet Package Manager » Manage NuGet Packages for Solution from the menu:
     
  2. Note: if the nuget package manager is missing, you can add it as a package source with the following steps: https://stackoverflow.com/questions/37293242/nuget-package-manager-no-packages-found-even-though-the-package-exists
  3. On the Browse tab, search for the package and click on the result to display some options:
     
  4. In the options, check the box next to your project and click Install:
     
  5. If a 'Review Changes' dialogue appears, click OK:
     

In Visual Studio 2019 for Mac

  1. Click Project » Manage NuGet Packages... from the menu:
     
  2. Search for the package, click on the result, and click Add Package:
     
  3. Quit and relaunch Visual Studio.

In MonoDevelop/Visual Studio for Mac

  1. Click Project » Add NuGet Packages from the menu:
     
  2. Search for the package, click on the result, and click Add Package:
     

Edit project file (.csproj)

Sometimes you may want to edit the project file directly (mainly to configure build steps). The project is a .csproj file, and can be edited from within the IDE.

In Visual Studio 2017

  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer pane, right-click on the project and choose Unload:
     
  3. Right-click on the project again and choose Edit <project name>.csproj:
     
  4. Make your changes in the editor that appears and save.
  5. When you're done, right-click on the project again and choose Reload Project:
     

In MonoDevelop/Visual Studio for Mac

  1. Open the Solution pad. If it's not visible, click View » Pads » Solution from the menu:
     
  2. From the Solution pad, right-click on the project and choose Tools » Edit File:
     
  3. Make your changes in the editor that appears and save.

Find compiled files

In Visual Studio 2017

  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer pane, right-click on the project and choose Open Folder in File Explorer:
     
  3. Navigate to bin\Debug (or bin\Release if you switched to release build configuration).

In MonoDevelop/Visual Studio for Mac

  1. Open the Solution pad. If it's not visible, click View » Pads » Solution from the menu:
     
  2. From the Solution pad, right-click on the project and choose Open Containing Folder:
     
  3. Navigate to bin/Debug (or bin/Release if you switched to release build configuration).

Add a reference to another DLL

In Visual Studio 2017

  1. Open the Solution Explorer pane. If it's not visible, click View » Solution Explorer from the menu:
     
  2. From the Solution Explorer pane, right-click on References and choose Add Reference...:
     
  3. From the 'Reference Manager' window, choose Browse in the left side, then click Browse.. at the bottom:
     
  4. Find the DLL you want to reference, select it, and click Add:
     
  5. From the 'Reference Manager' window, click OK:
     

In Rider

When opening a project for the first time, you must add a reference to StardewModdingAPI.dll for code completion to work.

  1. In the Explorer panel, select the Solution view
  2. Under the project, right-click on Dependencies and choose Reference...
  3. In the Add Reference window, click Add From... at the bottom
  4. Find the DLL you want to reference, select it, and click OK