Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added F# Support to BepInEx.PluginInfoProps #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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)">
<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.

## 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:

**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"
```