Jump to content

Modding:IDE reference: Difference between revisions

From Stardew Valley Wiki
imported>Pathoschild
copy from canimod.com with permission, dual-licensed CC BY-NC-SA for compatibility with wiki. Only author is Pathoschild.
 
imported>AnotherPillow
m add code formatting for bits that were intended to have it but used the wrong characters
 
(52 intermediate revisions by 16 users not shown)
Line 1: Line 1:
<pre>
←[[Modding:Index|Index]]
---
layout: default
title: Creating a SMAPI mod » IDE primer
intro: >
  This page is a quick reference for how to use Visual Studio 2017 or MonoDevelop/Xamarin when
  creating or editing a SMAPI mod. See <em><a href="creating-a-smapi-mod">creating a SMAPI mod</a></em>
  for the main guide.
---


## Before you start
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/Get Started|Modding:Modder Guide]] for the main guide.
* You should install [Visual Studio 2017 Community](https://www.visualstudio.com/vs/community/) (on Windows) or [MonoDevelop](http://www.monodevelop.com/) (on Linux/Mac).
* Reviewing [_C# Fundamentals for Absolute Beginners_](https://mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169)
is strongly recommended if you're new to programming C#.
* Here are some basic terms to remember:


  term    | definition
==Before you start==
  -------- | ----------
<ul>
  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/Xamarin on Linux/Mac.
<li>You should install [https://visualstudio.microsoft.com/vs/community/ Visual Studio Community] (Windows), [http://www.monodevelop.com/ MonoDevelop] (Linux), or [https://visualstudio.microsoft.com/vs/mac/ Visual Studio for Mac] (Mac).</li>
  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.
<li>Reviewing [https://mva.microsoft.com/en-us/training-courses/c-fundamentals-for-absolute-beginners-16169 ''C# Fundamentals for Absolute Beginners''] is strongly recommended if you're new to programming C#.</li>
  project  | A collection of source code + configuration + resources (like images) you edit in the IDE. Each project is compiled into its own DLL.
<li>Here are some basic terms to remember:
  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
{| class="wikitable"
<section id="create-project"></section>
|-
! 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 <samp>.dll</samp> 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).
|}</li>
</ul>


==Create a mod project==
<span id="create-project"></span>
Before you can write your mod code, you need to create a solution and project to contain it.
Before you can write your mod code, you need to create a solution and project to contain it.


### In Visual Studio 2017
===Windows (Visual Studio 2019/2022)===
# Open Visual Studio 2019/2022.
# Click ''Create a new project'' from the start screen.<br />[[File:Modding - IDE reference - create project (Visual Studio 1).png]]
# 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.<br />[[File:Modding - IDE reference - create project (Visual Studio 2).png| 589px]]
# In the ''configure your new project'' window: <ol><li>Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere").</li><li>Make sure "Place solution and project in the same directory" is ''not'' checked.</li><li>Click "Create" to to create the project.</li></ol>[[File:Modding - IDE reference - create project (Visual Studio 3).png|800px]]
# Next, select NET 6.0 and click "Create" to create the project. For VS 2022, this will be on the next page. <br />[[File:Screenshot 2021-12-16 140835.png]]


1. Open Visual Studio 2017.
===Windows/Mac/Linux (Rider 2024.x.x)===
2. Click _File » New » Project_ from the menu bar:
# Open Rider.
  ![](images/creating-a-smapi-mod-ide-primer/create-project-vs-1.png)
# Click ''New Solution'' from the project selection window. Rider may open to your previously opened project instead. If this is the case, click on ''File'', and ''New Solution''.<br />[[File:Rider IDE Guide - 1.png|800px|Click "New Solution".]]
3. In the 'New Project' window, choose _Visual C# » Class Library (.NET Framework)_:
# Click ''Class Library'' in the left pane.<br />[[File:Rider IDE Guide - 2.png|800px|Click "Class Library" in the left pane.]]
  ![](images/creating-a-smapi-mod-ide-primer/create-project-vs-2.png)
# Click where it says ''from <SDK version>''.<br />[[File:Rider IDE Guide - 3.png|800px|Click where it says "from <SDK Version>"]]
4. Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like
# Select ''SDK 6.0'' so you can create a ''.NET 6.0'' project.<br />[[File:Rider IDE Guide - 4.png|800px|Select "SDK 6.0".]]
  "PineapplesEverywhere"): 
# Select ''net6.0'' in the dropdown to the right of ''Target framework''.<br />[[File:Rider IDE Guide - 6.png|800px|Select "net6.0" in the dropdown.]]
  ![](images/creating-a-smapi-mod-ide-primer/create-project-vs-3.png)
# Click the ''Create'' button.<br />[[File:Rider IDE Guide - 7.png|800px|Click the "Create" button.]]
5. Make sure "create directory for solution" is checked, and click _OK_: 
  ![](images/creating-a-smapi-mod-ide-primer/create-project-vs-4.png)


### In MonoDevelop/Xamarin
===Linux (MonoDevelop)===
# Open MonoDevelop.
# Click ''File » New Solution'' from the menu bar:<br />[[File:Modding - IDE reference - create project (MonoDevelop 1).png]]
# In the 'New Project' window, choose ''.NET » Library'' and click ''Next'':<br />[[File:Modding - IDE reference - create project (MonoDevelop 2).png]]
# Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):<br />[[File:Modding - IDE reference - create project (MonoDevelop 3).png]]
# Make sure "create a project directory within the solution directory" is checked, and click ''Create'':<br />[[File:Modding - IDE reference - create project (MonoDevelop 4).png]]


1. Open MonoDevelop/Xamarin.
===MacOS (Visual Studio 2019 for Mac)===
2. Click _File » New Solution_ from the menu bar: 
  ![](images/creating-a-smapi-mod-ide-primer/create-project-monodev-1.png)
3. In the 'New Project' window, choose _.NET » Library_ and click _Next_: 
  ![](images/creating-a-smapi-mod-ide-primer/create-project-monodev-2.png)
4. Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like
  "PineapplesEverywhere"): 
  ![](images/creating-a-smapi-mod-ide-primer/create-project-monodev-3.png)
5. Make sure "create a project directory within the solution directory" is checked, and click _Create_: 
  ![](images/creating-a-smapi-mod-ide-primer/create-project-monodev-4.png)


## Set the target framework
# Install the .NET 6.0 SDK if you haven't already (check [[Modding:Modder_Guide/Get_Started#Requirements|here]] for your system).<br />[[File:1a NET website.png|600px]]
<section id="set-target-framework"></section>
# Open Visual Studio for Mac.
# Click ''File » New Solution'' from the menu bar:<br />[[File:VS Mac 1 newsolution.png|600px]]
# Select the correct type of class library:<br />[[File:VS Mac 2 createlibrary.png|600px]]
# Set it to target '''.NET 6.0.''':<br />[[File:VS Mac 3 setframework.png|600px]]
# Enter a descriptive mod name for the project. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):<br />[[File:VS Mac 4 nameproject.png|600px]]


The 'target framework' is the version of .NET Framework your code uses, which affects the version
===MacOS (Visual Studio for Mac)===
needed to run your mod. The recommended target framework is .NET Framework 4.5, which is the
# Open Visual Studio for Mac.
version SMAPI itself targets.
# Click ''File » New Solution'' from the menu bar:<br />[[File:Modding - IDE reference - create project (Visual Studio for Mac 1).png|200px]]
# In the 'New Project' window, choose ''.NET » Library'' and click ''Next'':<br />[[File:Modding - IDE reference - create project (Visual Studio for Mac 2).png|750px]]
# Enter a descriptive mod name. By convention, the name should be one word with mixed caps (like "PineapplesEverywhere"):<br />[[File:Modding - IDE reference - create project (Visual Studio for Mac 3).png|750px]]
# Make sure "create a project directory within the solution directory" is checked, and click ''Create'':<br />[[File:Modding - IDE reference - create project (Visual Studio for Mac 4).png|750px]]


### In Visual Studio 2017
==Set the target framework==
<span id="set-target-framework"></span>
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 6.0, which is the version SMAPI itself targets. '''Please find the subsection below for your OS''' (Windows/Mac).


1. Open the Solution Explorer pane. If it's not visible, click _View » Solution Explorer_
===In Windows Visual Studio 2019/2022===
  from the menu:
'''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 <code>helper.Events</code> in the <code>Entry(IModhelper helper)</code> method and <code>ButtonPressedEventArgs</code> from the <code>Entry(IModHelper helper)</code> method, try the project-creation and code-copy/paste process again with Visual Studio 2019/2022 instead.
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-vs.png)
2. From the Solution Explorer, right-click on the project and choose _Properties_: 
  ![](images/creating-a-smapi-mod-ide-primer/change-target-framework-vs-1.png)
3. On the _Application_ tab, change the _Target Framework_ dropdown to _.NET Framework 4.5_: 
  ![](images/creating-a-smapi-mod-ide-primer/change-target-framework-vs-2.png)
4. A dialogue may appear asking you to confirm the change. Click 'Yes' to confirm: 
  ![](images/creating-a-smapi-mod-ide-primer/change-target-framework-vs-3.png)


### In MonoDevelop/Xamarin


1. Open the Solution pad. If it's not visible, click _View » Pads » Solution_ from the
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
  menu:
# From the Solution Explorer, right-click on the project and choose ''Properties'':<br />[[File:Modding - IDE reference - change target framework (Visual Studio 1).png]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-monodev.png)
# On the ''Application'' tab, change the ''Target Framework'' dropdown to ''.NET 6.0'':<br />[[File:Modding - IDE reference - change target framework (Visual Studio 2).png|800px]]
2. From the Solution pad, right-click on the project and choose _Options_:
# A dialogue may appear asking you to confirm the change. Click 'Yes' to confirm:<br />[[File:Modding - IDE reference - change target framework (Visual Studio 3).png]]
  ![](images/creating-a-smapi-mod-ide-primer/change-target-framework-monodev-1.png)
3. On the _Build » General_ tab, change the _Target Framework_ dropdown to _Mono / .NET 4.5_:
  ![](images/creating-a-smapi-mod-ide-primer/change-target-framework-monodev-2.png)


## Add a file
===In Visual Studio 2019 for Mac===
<section id="add-file"></section>


### In Visual Studio 2017
If you followed the instructions above to set up your project, your framework should already be set to .NET 6.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 6.0.)


1. Open the Solution Explorer pane. If it's not visible, click _View » Solution Explorer_
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:
  from the menu:
# Open the .csproj file for editing:<br />[[File:VS Mac 7 editcsproj.png|600px]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-vs.png)
# Replace your mod's <samp>.csproj</samp> file with this (where <code>EXAMLE_MOD_NAME</code> is your solution's name):
2. From the Solution Explorer pane, right-click on the project and choose _Add » New Item_: 
<syntaxhighlight lang="xml">
  ![](images/creating-a-smapi-mod-ide-primer/create-file-vs-1.png)
<Project Sdk="Microsoft.NET.Sdk">
3. From the 'Add New Item' window, choose the file type (usually _Visual C# Item » Class_): 
  <PropertyGroup>
  ![](images/creating-a-smapi-mod-ide-primer/create-file-vs-2.png)
    <AssemblyName>EXAMPLE_MOD_NAME</AssemblyName>
4. Enter a descriptive file name and click _Add_: 
    <RootNamespace>EXAMPLE_MOD_NAME</RootNamespace>
  ![](images/creating-a-smapi-mod-ide-primer/create-file-vs-3.png)
    <Version>1.0.0</Version>
    <TargetFramework>net6.0</TargetFramework>
  </PropertyGroup>


### In MonoDevelop/Xamarin
  <ItemGroup>
    <PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.0.0" />
  </ItemGroup>
</Project>
</syntaxhighlight>


1. Open the Solution pad. If it's not visible, click _View » Pads » Solution_ from the
# If the mod uses [[Modding:Modder Guide/APIs/Harmony|Harmony]], add <code><nowiki><EnableHarmony>true</EnableHarmony></nowiki></code> to the property group.
  menu:
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-monodev.png)
2. From the Solution pad, right-click on the project to delete and choose _Add » New File_: 
  ![](images/creating-a-smapi-mod-ide-primer/create-file-monodev-1.png)
3. From the 'New File' window, choose the file type (usually _General » Empty Class_): 
  ![](images/creating-a-smapi-mod-ide-primer/create-file-monodev-2.png)
4. Enter a descriptive file name and click _New_: 
  ![](images/creating-a-smapi-mod-ide-primer/create-file-monodev-3.png)


## Delete a file
===In MonoDevelop/Visual Studio for Mac===
<section id="delete-file"></section>
<p style="color:red;">'''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.'''</p>


### In Visual Studio 2017
# Open the Solution pad. If it's not visible, click ''View » Pads » Solution'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (MonoDevelop).png]]
# From the Solution pad, right-click on the project and choose ''Options'':<br />[[File:Modding - IDE reference - change target framework (MonoDevelop 1).png]]
# On the ''Build » General'' tab, change the ''Target Framework'' dropdown to ''Mono / .NET 6.0'':<br />[[File:Modding - IDE reference - change target framework (MonoDevelop 2).png]]


1. Open the Solution Explorer pane. If it's not visible, click _View » Solution Explorer_
==Add a file==
  from the menu: 
<span id="add-file"></span>
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-vs.png)
2. From the Solution Explorer pane, right-click on the file to delete and choose _Delete_: 
  ![](images/creating-a-smapi-mod-ide-primer/delete-file-vs.png)


### In MonoDevelop/Xamarin
===In Visual Studio 2017===
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
# From the Solution Explorer pane, right-click on the project and choose ''Add » New Item'':<br />[[File:Modding - IDE reference - create file (Visual Studio 1).png]]
# From the 'Add New Item' window, choose the file type (usually ''Visual C# Item » Class''):<br />[[File:Modding - IDE reference - create file (Visual Studio 2).png]]
# Enter a descriptive file name and click ''Add'':<br />[[File:Modding - IDE reference - create file (Visual Studio 3).png]]


1. Open the Solution pad. If it's not visible, click _View » Pads » Solution_ from the
===In MonoDevelop/Visual Studio for Mac===
  menu:
# Open the Solution pad. If it's not visible, click ''View » Pads » Solution'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (MonoDevelop).png]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-monodev.png)
# From the Solution pad, right-click on the project to delete and choose ''Add » New File'':<br />[[File:Modding - IDE reference - create file (MonoDevelop 1).png]]
2. From the Solution pad, right-click on the file to delete and choose _Remove_:
# From the 'New File' window, choose the file type (usually ''General » Empty Class''):<br />[[File:Modding - IDE reference - create file (MonoDevelop 2).png]]
  ![](images/creating-a-smapi-mod-ide-primer/delete-file-monodev.png)
# Enter a descriptive file name and click ''New'':<br />[[File:Modding - IDE reference - create file (MonoDevelop 3).png]]


## Add a NuGet package
==Delete a file==
<section id="add-nuget"></section>
<span id="delete-file"></span>


### In Visual Studio 2017
===In Visual Studio 2017===
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
# From the Solution Explorer pane, right-click on the file to delete and choose ''Delete'':<br />[[File:Modding - IDE reference - delete file (Visual Studio).png]]


1. Click _Tools » NuGet Package Manager » Manage NuGet Packages for Solution_ from the menu:
===In MonoDevelop/Visual Studio for Mac===
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-vs-1.png)
# Open the Solution pad. If it's not visible, click ''View » Pads » Solution'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (MonoDevelop).png]]
2. On the _Browse_ tab, search for the package and click on the result to display some options: 
# From the Solution pad, right-click on the file to delete and choose ''Remove'':<br />[[File:Modding - IDE reference - delete file (MonoDevelop).png]]
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-vs-2.png)
3. In the options, check the box next to your project and click _Install_: 
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-vs-3.png)
4. If a 'Review Changes' dialogue appears, click _OK_:
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-vs-4.png)


### In MonoDevelop/Xamarin
==Add a NuGet package==
<span id="add-nuget"></span>
===In Visual Studio Code===
# As of August 31, 2024, Visual Studio is now retired for Mac. You may be using Visual Studio Code to edit your game files now. As of right now, the built-in Nuget Package Manager with the C# Dev Kit does not work with SDK 6.0. You can download another extension called "Nuget Package Manager GUI" by aliasadidev and the flow will be similar to the process below for Visual Studio 2019. If you do not want to download this, you can use the Terminal below.
# With your Project open, open a new Terminal in Visual Studio Code.
# Type in <code>dotnet add <YOUR_MOD_NAME_HERE> package Pathoschild.Stardew.ModBuildConfig</code> to the terminal and press enter. Change <code><YOUR_MOD_NAME_HERE></code> to the name of your Mod.
# You should get a bunch of log messages like in the picture below.
::[[File:Nuget package cli.png|thumb|left|600px|adding StardewModdingApi nuget package to your project]]{{Clear}}


1. Click _Project » Add NuGet Packages_ from the menu:
===In Visual Studio 2019/2022===
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-monodev-1.png)
# Click ''Tools » NuGet Package Manager » Manage NuGet Packages for Solution'' from the menu:<br />[[File:Modding - IDE reference - add NuGet package (Visual Studio 1).png]]
2. Search for the package, click on the result, and click _Add Package_:
# 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
  ![](images/creating-a-smapi-mod-ide-primer/add-nuget-package-monodev-2.png)
# On the ''Browse'' tab, search for the package and click on the result to display some options:<br />[[File:Modding - IDE reference - add NuGet package (Visual Studio 2).png]]
# In the options, check the box next to your project and click ''Install'':<br />[[File:Modding - IDE reference - add NuGet package (Visual Studio 3).png]]
# If a 'Review Changes' dialogue appears, click ''OK'':<br />[[File:Modding - IDE reference - add NuGet package (Visual Studio 4).png]]


## Edit project file (`.csproj`)
===In Visual Studio 2019 for Mac===
<section id="edit-project"></section>
# Click ''Project » Manage NuGet Packages...'' from the menu:<br />[[File:VS Mac 5 managenuget.png|600px]]
# Search for the package, click on the result, and click ''Add Package'':<br />[[File:VS Mac 6 addnuget.png|600px]]
# Quit and relaunch Visual Studio.


Sometimes you may want to edit the project file directly (mainly to configure build steps). The
===In MonoDevelop/Visual Studio for Mac===
project is a `.csproj` file, and can be edited from within the IDE.
# Click ''Project » Add NuGet Packages'' from the menu:<br />[[File:Modding - IDE reference - add NuGet package (MonoDevelop 1).png]]
# Search for the package, click on the result, and click ''Add Package'':<br />[[File:Modding - IDE reference - add NuGet package (MonoDevelop 2).png]]


### In Visual Studio 2017
==Edit project file (<samp>.csproj</samp>)==
<span id="edit-project"></span>


1. Open the Solution Explorer pane. If it's not visible, click _View » Solution Explorer_
Sometimes you may want to edit the project file directly (mainly to configure build steps). The project is a <samp>.csproj</samp> file, and can be edited from within the IDE.
  from the menu: 
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-vs.png)
2. From the Solution Explorer pane, right-click on the project and choose _Unload_: 
  ![](images/creating-a-smapi-mod-ide-primer/edit-project-file-vs-1.png)
3. Right-click on the project again and choose _Edit &lt;project name&gt;.csproj_: 
  ![](images/creating-a-smapi-mod-ide-primer/edit-project-file-vs-2.png)
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_: 
  ![](images/creating-a-smapi-mod-ide-primer/edit-project-file-vs-3.png)


### In MonoDevelop/Xamarin
===In Visual Studio 2017===
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
# From the Solution Explorer pane, right-click on the project and choose ''Unload'':<br />[[File:Modding - IDE reference - edit project (Visual Studio 1).png]]
# Right-click on the project again and choose ''Edit &lt;project name&gt;.csproj'':<br />[[File:Modding - IDE reference - edit project (Visual Studio 2).png]]
# Make your changes in the editor that appears and save.
# When you're done, right-click on the project again and choose ''Reload Project'':<br />[[File:Modding - IDE reference - edit project (Visual Studio 3).png]]


1. Open the Solution pad. If it's not visible, click _View » Pads » Solution_ from the
===In MonoDevelop/Visual Studio for Mac===
  menu:
# Open the Solution pad. If it's not visible, click ''View » Pads » Solution'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (MonoDevelop).png]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-monodev.png)
# From the Solution pad, right-click on the project and choose ''Tools » Edit File'':<br />[[File:Modding - IDE reference - edit project (MonoDevelop).png]]
2. From the Solution pad, right-click on the project and choose _Tools » Edit File_:
# Make your changes in the editor that appears and save.
  ![](images/creating-a-smapi-mod-ide-primer/edit-project-file-monodev.png)
3. Make your changes in the editor that appears and save.


## Find compiled files
==Find compiled files==
<section id="build-output"></section>
<span id="build-output"></span>


### In Visual Studio 2017
===In Visual Studio 2017===
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
# From the Solution Explorer pane, right-click on the project and choose ''Open Folder in File Explorer'':<br />[[File:Modding - IDE reference - view build output (Visual Studio).png]]
# Navigate to <samp>bin\Debug</samp> (or <samp>bin\Release</samp> if you switched to release build configuration).


1. Open the Solution Explorer pane. If it's not visible, click _View » Solution Explorer_
===In MonoDevelop/Visual Studio for Mac===
  from the menu:
# Open the Solution pad. If it's not visible, click ''View » Pads » Solution'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (MonoDevelop).png]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-vs.png)
# From the Solution pad, right-click on the project and choose ''Open Containing Folder'':<br />[[File:Modding - IDE reference - view build output (MonoDevelop).png]]
2. From the Solution Explorer pane, right-click on the project and choose _Open Folder in File Explorer_:
# Navigate to <samp>bin/Debug</samp> (or <samp>bin/Release</samp> if you switched to release build configuration).
  ![](images/creating-a-smapi-mod-ide-primer/view-build-output-vs.png)
3. Navigate to the `bin\Debug` (or `bin\Release` if you switched to release build configuration).


### In MonoDevelop/Xamarin
==Add a reference to another DLL==
<span id="add-reference"></span>


1. Open the Solution pad. If it's not visible, click _View » Pads » Solution_ from the
===In Visual Studio 2017===
  menu:
# Open the Solution Explorer pane. If it's not visible, click ''View » Solution Explorer'' from the menu:<br />[[File:Modding - IDE reference - show solution pane (Visual Studio).png]]
  ![](images/creating-a-smapi-mod-ide-primer/show-solution-pane-monodev.png)
# From the Solution Explorer pane, right-click on ''References'' and choose ''Add Reference...'':<br />[[File:Modding - IDE reference - add reference (Visual Studio 1).png]]
2. From the Solution pad, right-click on the project and choose _Open Containing Folder_:
# From the 'Reference Manager' window, choose ''Browse'' in the left side, then click ''Browse..'' at the bottom:<br />[[File:Modding - IDE reference - add reference (Visual Studio 2).png]]
  ![](images/creating-a-smapi-mod-ide-primer/view-build-output-monodev.png)
# Find the DLL you want to reference, select it, and click ''Add'':<br />[[File:Modding - IDE reference - add reference (Visual Studio 3).png]]
3. Navigate to the `bin/Debug` (or `bin/Release` if you switched to release build configuration).
# From the 'Reference Manager' window, click ''OK'':<br />[[File:Modding - IDE reference - add reference (Visual Studio 4).png]]
</pre>


[[Category:Modding|IDE reference]]
===In Rider===
When opening a project for the first time, you must add a reference to StardewModdingAPI.dll for code completion to work.
# In the Explorer panel, select the ''Solution'' view
# Under the project, right-click on ''Dependencies'' and choose ''Reference...''
# In the Add Reference window, click ''Add From...'' at the bottom
# Find the DLL you want to reference, select it, and click ''OK''
 
 
[[Category:Modding]]
 
[[es:Modding:Referencia IDE]]
[[ru:Модификации:Настройка среды разработки]]
[[zh:模组:IDE 参考]]

Latest revision as of 08:37, 3 May 2026

←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.

Windows/Mac/Linux (Rider 2024.x.x)

  1. Open Rider.
  2. Click New Solution from the project selection window. Rider may open to your previously opened project instead. If this is the case, click on File, and New Solution.
    Click "New Solution".
  3. Click Class Library in the left pane.
    Click "Class Library" in the left pane.
  4. Click where it says from <SDK version>.
    Click where it says "from <SDK Version>"
  5. Select SDK 6.0 so you can create a .NET 6.0 project.
    Select "SDK 6.0".
  6. Select net6.0 in the dropdown to the right of Target framework.
    Select "net6.0" in the dropdown.
  7. Click the Create button.
    Click the "Create" button.

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 6.0 SDK if you haven't already (check here for your system).
  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 6.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 6.0, which is the version SMAPI itself targets. Please find the subsection below for your OS (Windows/Mac).

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 6.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 6.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 6.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>net6.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 6.0:

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 Code

  1. As of August 31, 2024, Visual Studio is now retired for Mac. You may be using Visual Studio Code to edit your game files now. As of right now, the built-in Nuget Package Manager with the C# Dev Kit does not work with SDK 6.0. You can download another extension called "Nuget Package Manager GUI" by aliasadidev and the flow will be similar to the process below for Visual Studio 2019. If you do not want to download this, you can use the Terminal below.
  2. With your Project open, open a new Terminal in Visual Studio Code.
  3. Type in dotnet add <YOUR_MOD_NAME_HERE> package Pathoschild.Stardew.ModBuildConfig to the terminal and press enter. Change <YOUR_MOD_NAME_HERE> to the name of your Mod.
  4. You should get a bunch of log messages like in the picture below.
adding StardewModdingApi nuget package to your project

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