BepInEx Mods: How we generated our first BepInEx project

From Astrea Wiki
Jump to navigation Jump to search

We followed the BepinEx documentation: https://docs.bepinex.dev/articles/dev_guide/plugin_tutorial/1_setup.html but we suffered trying to understand some points:

Using other .NET then .NET 6 seems not working. We used the most recent .NET 8 and it didn`t work correctly to generate the BepInEx project.
To resolve this problem we followed to uninstall and install the .NET6 or just follow these steps:

Step-by-Step:

Note: Any .NET 6.* version must work

  • Add global.json on root folder that you trying to generate your BepInEx project.
  • Open CMD prompt in your root folder and find the name of your .NET version using this command: `dotnet --list-sdks`. It will generate a output like this:
6.0.408 [C:\Program Files\dotnet\sdk]
8.0.200 [C:\Program Files\dotnet\sdk]
  • Put the code on global.json like this example:
{
    "sdk": 
    {
      "version": "6.0.408"
    }
}

Note: Just explaning this command above: `dotnet new bepinex5plugin -n MyFirstPlugin -T <TFM> -U <Unity> `

  • In our game <TFM> is net46 because our mscorlib.dll version is newer then 4.0.0.0 following this path in case your want to see : ...\Astrea\Astrea_Data\Managed
  • The <Unity> is the unity version that we used to make the Astrea game, just put the current. For example now is : 2020.3.43 .
  • Just open this path with Notepad++ for example: ...\common\Astrea\Astrea_Data\globalgamemanagers > you will see a readable version of unity in the top of file.

how your MyFirstPlugin.csproj will be generated:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net46</TargetFramework>
    <AssemblyName>MyFirstPlugin</AssemblyName>
    <Description>My first plugin</Description>
    <Version>1.0.0</Version>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
    <PackageReference Include="BepInEx.Core" Version="5.*" />
    <PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
    <PackageReference Include="UnityEngine.Modules" Version="2020.3.43" IncludeAssets="compile" />
  </ItemGroup>
  
  <ItemGroup Condition="'$(TargetFramework.TrimEnd(`0123456789`))' == 'net'">
    <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
  </ItemGroup>
</Project>

Go Back to Mods page: Mods