Skip to content
Open
Show file tree
Hide file tree
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
25 changes: 22 additions & 3 deletions BepInEx.PluginInfoProps/BepInEx.PluginInfoProps.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<Project>
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)GeneratedFile.cs">
<PropertyGroup>
<FileExtension Condition="$(MSBuildProjectExtension) == '.fsproj'">fs</FileExtension>
<FileExtension Condition="$(MSBuildProjectExtension) == '.csproj'">cs</FileExtension>
</PropertyGroup>
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)GeneratedFile.$(FileExtension)">
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The target Outputs path ($(IntermediateOutputPath)GeneratedFile.$(FileExtension)) doesn’t match the file actually written/included ($(IntermediateOutputPath)MyPluginInfo.$(FileExtension)). This prevents incremental build from correctly skipping the target and can cause it to run every build. Align Outputs with the real generated file path (or update GeneratedFilePath to match).

Suggested change
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)GeneratedFile.$(FileExtension)">
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)MyPluginInfo.$(FileExtension)">

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

FileExtension is only set for .csproj/.fsproj, but the target still runs and unconditionally adds $(GeneratedFilePath) to @(Compile). If this .props is imported by another project type (e.g., .vbproj), $(FileExtension) will be empty and this can generate/include MyPluginInfo. (no extension), breaking the build. Add a target-level Condition (e.g., only run when $(FileExtension) is cs or fs) and/or set a safe default / emit a clear error for unsupported project types.

Suggested change
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)GeneratedFile.$(FileExtension)">
<Target Name="AddGeneratedFile" BeforeTargets="BeforeCompile;CoreCompile" Condition=" '$(FileExtension)' == 'cs' Or '$(FileExtension)' == 'fs' " Inputs="$(MSBuildAllProjects)" Outputs="$(IntermediateOutputPath)GeneratedFile.$(FileExtension)">

Copilot uses AI. Check for mistakes.
<PropertyGroup>
<BepInExPluginGuid Condition="'$(BepInExPluginGuid)' == ''">$(AssemblyName)</BepInExPluginGuid>
<BepInExPluginName Condition="'$(BepInExPluginName)' == ''">$(Product)</BepInExPluginName>
<BepInExPluginVersion Condition="'$(BepInExPluginVersion)' == ''">$(Version)</BepInExPluginVersion>
<GeneratedText><![CDATA[
<GeneratedText Condition="'$(FileExtension)' == 'cs'"><![CDATA[
namespace $(RootNamespace)
{
internal static class MyPluginInfo
Expand All @@ -15,10 +19,25 @@ namespace $(RootNamespace)
}
}
]]></GeneratedText>
<GeneratedFilePath>$(IntermediateOutputPath)MyPluginInfo.cs</GeneratedFilePath>
<GeneratedText Condition="'$(FileExtension)' == 'fs'"><![CDATA[
namespace $(RootNamespace)

module internal MyPluginInfo =
[<Literal>]
let PLUGIN_GUID: string = "$(BepInExPluginGuid)"
[<Literal>]
let PLUGIN_NAME: string = "$(BepInExPluginName)"
[<Literal>]
let PLUGIN_VERSION: string = "$(BepInExPluginVersion)"
]]></GeneratedText>
<GeneratedFilePath>$(IntermediateOutputPath)MyPluginInfo.$(FileExtension)</GeneratedFilePath>
</PropertyGroup>
<ItemGroup>
<FSharpOrderedCompile Include="@(Compile)" Condition="'$(FileExtension)' == 'fs'"/> <!-- Here we save F#'s ordered compilation -->
<Compile Remove="@(FSharpOrderedCompile)" Condition="'$(FileExtension)' == 'fs'"/> <!-- because FSC cares about the order. -->

<Compile Include="$(GeneratedFilePath)" />
<Compile Include="@(FSharpOrderedCompile)" Condition="'$(FileExtension)' == 'fs'"/> <!-- Add after so PluginInfo is accessible.-->
<FileWrites Include="$(GeneratedFilePath)" />
</ItemGroup>
<WriteLinesToFile Lines="$(GeneratedText)" File="$(GeneratedFilePath)" WriteOnlyWhenDifferent="true" Overwrite="true" />
Expand Down
20 changes: 16 additions & 4 deletions BepInEx.PluginInfoProps/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
## BepInEx PluginInfo generator

Generates `MyPluginInfo.cs` based on csproj tags.
Generates a `MyPluginInfo.cs`, or `.fs`, based on project tags.

Supports C# & F# projects, and will read the `.csproj` or `.fsproj` to determine values.
Comment on lines +3 to +5
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

README says it generates MyPluginInfo.cs, or .fs, but the build writes MyPluginInfo.$(FileExtension) (i.e., MyPluginInfo.fs). Also, the generated file includes a namespace $(RootNamespace) wrapper (see props), which isn’t reflected in either the C# or F# examples. Update the wording and samples so they match the actual generated output.

Copilot uses AI. Check for mistakes.

## Basic usage

Define the following properties in your `csproj`:
Define the following properties in your project file:

```xml
<AssemblyName>Example.Plugin</AssemblyName>
Expand All @@ -14,13 +16,23 @@ Define the following properties in your `csproj`:

this will generate the following class:
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

The text "this will generate the following class:" is no longer accurate for F# output (it generates a module). Consider rephrasing to something language-neutral (e.g., "this will generate the following code") or splitting wording per language section.

Suggested change
this will generate the following class:
this will generate the following code:

Copilot uses AI. Check for mistakes.

**C#**
```cs
using System;

internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "Example.Plugin";
public const string PLUGIN_NAME = "My first plugin";
public const string PLUGIN_VERSION = "1.0.0";
}
```

**F#**
```fsharp
module internal MyPluginInfo =
[<Literal>]
let PLUGIN_GUID: string = "Example.Plugin"
[<Literal>]
let PLUGIN_NAME: string = "My first plugin"
[<Literal>]
let PLUGIN_VERSION: string = "1.0.0"
```
Loading