Hamunii.BepInEx.AutoPlugin 2.0.1

dotnet add package Hamunii.BepInEx.AutoPlugin --version 2.0.1
                    
NuGet\Install-Package Hamunii.BepInEx.AutoPlugin -Version 2.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Hamunii.BepInEx.AutoPlugin" Version="2.0.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Hamunii.BepInEx.AutoPlugin" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Hamunii.BepInEx.AutoPlugin">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Hamunii.BepInEx.AutoPlugin --version 2.0.1
                    
#r "nuget: Hamunii.BepInEx.AutoPlugin, 2.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Hamunii.BepInEx.AutoPlugin@2.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Hamunii.BepInEx.AutoPlugin&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Hamunii.BepInEx.AutoPlugin&version=2.0.1
                    
Install as a Cake Tool

BepInEx.AutoPlugin

NuGet

BepInEx.AutoPlugin is an incremental C# source generator that takes the following properties from your project:

<PropertyGroup>
  <AssemblyName>com.example.ExamplePlugin</AssemblyName>
  <AssemblyTitle>ExamplePlugin</AssemblyTitle>
  <Version>0.1.0</Version>
</PropertyGroup>

And generates a partial class for your partial plugin class decorated with the BepInAutoPluginAttribute, decorating the generated class with the BepInPluginAttribute using the above properties:

[BepInEx.BepInPlugin(ExamplePlugin.Id, "ExamplePlugin", "0.1.0")]
partial class ExamplePlugin : BaseUnityPlugin
{
    public const string Id = "com.example.ExamplePlugin";
    public static string Name => "ExamplePlugin";
    public static string Version => "0.1.0";
}

A PatcherAutoPluginAttribute also exists for BepInEx 6 preloader patchers.

Usage

Add the following to your csproj:

<ItemGroup>
  <PackageReference Include="Hamunii.BepInEx.AutoPlugin" Version="2.0.*" PrivateAssets="all" />
</ItemGroup>

Mark your plugin class partial, and decorate it with the BepInAutoPluginAttribute:

[BepInAutoPlugin]
public partial class ExamplePlugin : BaseUnityPlugin
{
}

And you're done! You don't need to manually include the BepInPluginAttribute, as the generated partial class includes that.

You can also access all the properties in your code, as they are public members in your class:

[BepInAutoPlugin]
public partial class ExamplePlugin : BaseUnityPlugin
{
    void Awake()
    {
        Logger.LogInfo($"Plugin {Name} version {Version} is loaded!");
    }
}

Overriding Properties

AutoPlugin allows overriding any of the properties with the optional attribute arguments:

[BepInAutoPlugin(id: "com.example.MyOverrideId", name: "My Override Name", version: "1.2.3")]
public partial class ExamplePlugin : BaseUnityPlugin
{
}

MSBuild Configuration

AutoPlugin allows stripping version build metadata to turn 1.0.0-beta+1234567890 into 1.0.0-beta for the Version property by setting the following in your csproj:

<PropertyGroup>
  <BepInAutoPluginStripBuildMetadata>true</BepInAutoPluginStripBuildMetadata>
</PropertyGroup>

Note that this will do nothing on BepInEx 5 as it only accepts a version number without a pre-release version or build metadata, so it strips both.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.1 934 6/24/2025
2.0.0 156 6/20/2025