Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions BepInEx.AutoPlugin/AutoPluginGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -59,6 +59,22 @@ public void Initialize(GeneratorInitializationContext context)
return (string?)attribute?.ConstructorArguments.Single().Value;
}

private static bool IsPreferStripInformationalVersionInfo(GeneratorExecutionContext context)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ShouldStripInformationalVersionSuffix is way easier to read.

{
var bepInExAssemblyReference =
context.Compilation.SourceModule.ReferencedAssemblySymbols.FirstOrDefault(x =>
x.Identity.Name == "BepInEx"
);

// BepInEx 5 doesn't support plugins having version pre-release or build metadata
// such as 1.0.0-beta or 1.0.0+97ec53d20958b88581680d4d3c15ba59a8900ed5
bool isBepInEx5 =
bepInExAssemblyReference is not null
&& bepInExAssemblyReference.Identity.Version.Major == 5;

return isBepInEx5;
}

private enum AutoType
{
Plugin,
Expand Down Expand Up @@ -110,7 +126,19 @@ public void Execute(GeneratorExecutionContext context)
var arguments = attribute.ConstructorArguments.Select(x => x.IsNull ? null : (string)x.Value!).ToArray();
var id = arguments[0] ?? context.Compilation.AssemblyName;
var name = arguments[1] ?? GetAssemblyAttribute(context, nameof(AssemblyTitleAttribute)) ?? context.Compilation.AssemblyName;
var version = arguments[2] ?? GetAssemblyAttribute(context, nameof(AssemblyInformationalVersionAttribute)) ?? GetAssemblyAttribute(context, nameof(AssemblyVersionAttribute));
var version = arguments[2];
if (version is null)
{
var informationalVersion =
GetAssemblyAttribute(context, nameof(AssemblyInformationalVersionAttribute));

if (informationalVersion is null)
version = GetAssemblyAttribute(context, nameof(AssemblyVersionAttribute));
else if (IsPreferStripInformationalVersionInfo(context))
version = informationalVersion.Split('-', '+')[0];
else
version = informationalVersion;
}

var attributeName = type switch
{
Expand Down