-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
package as MSBuildSdk, rather than nuget package with build assets
- Loading branch information
Showing
8 changed files
with
92 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,101 @@ | ||
# Lethal Company Plugin SDK | ||
|
||
Get modding Lethal Company easier, faster, and *better*. | ||
An [MSBuild Sdk](https://learn.microsoft.com/en-us/visualstudio/msbuild/how-to-use-project-sdk?view=vs-2022) for creating Lethal Company mods that: | ||
|
||
- Optimizes Build Defaults | ||
- Enables Modern Language Features with [`PolySharp`](https://github.com/Sergio0694/PolySharp) | ||
- References Publicized Binaries from [`LethalAPI.GameLibs`](https://github.com/dhkatz/LethalAPI.GameLibs) | ||
- Creates Thunderstore Packages | ||
- And More... | ||
|
||
|
||
## Usage | ||
|
||
- Add a reference to the `LethalCompany.Plugin.Sdk` package to an empty Class Library targeting `netstandard2.1` | ||
To start using the Sdk, create a new Class Library: | ||
```bash | ||
$ dotnet new classlib -n {NAME} | ||
``` | ||
|
||
In the new `.csproj`, update the `Sdk="Microsoft.NET.Sdk"` attribute at the top of the file to `Sdk="LethalCompany.Plugin.Sdk/{VERSION}"`, and replace any existing content with metadata about the plugin: | ||
```xml | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Project Sdk="LethalCompany.Plugin.Sdk/1.0.0"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<Title>Plugin Example</Title> | ||
<Description>My example plugin!</Description> | ||
<PluginId>example.plugin</PluginId> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="LethalCompany.Plugin.Sdk" Version="..." PrivateAssets="all" /> | ||
</ItemGroup> | ||
</Project> | ||
``` | ||
|
||
- Define your plugin metadata in your `.csproj` | ||
```xml | ||
<PropertyGroup> | ||
<Title>Plugin Example</Title> | ||
<Description>My example plugin!</Description> | ||
<PluginId>example.plugin</PluginId> | ||
<ThunderId>Example_Plugin</ThunderId> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ThunderReference Include="..." /> | ||
</ItemGroup> | ||
``` | ||
|
||
- Create your plugin class | ||
Add a new `.cs` file, and define the plugin: | ||
```csharp | ||
[BepInPlugin(GeneratedPluginInfo.Identifier, GeneratedPluginInfo.Name, GeneratedPluginInfo.Version)] | ||
public sealed class SamplePlugin : BaseUnityPlugin | ||
{ | ||
// ... | ||
} | ||
``` | ||
> _The Sdk creates a `GeneratedPluginInfo` class from the metadata provided in your project for usage in code._ | ||
> _The Sdk generates a `GeneratedPluginInfo` class from the metadata provided in your project for usage in code._ | ||
> | ||
> _The name of the generated class can be changed using the `<PluginInfoTypeName>...</PluginInfoTypeName>` MSBuild property._ | ||
|
||
- Use `dotnet publish` to create a package that's ready for upload to Thunderstore | ||
``` | ||
> dotnet publish -c Release -o package | ||
... | ||
Zipping directory ".\bin\Release\netstandard2.1\publish\" to ".\package\Example_Plugin-1.0.0.zip". | ||
``` | ||
|
||
|
||
## Features | ||
> _The name of the generated class can be changed using the `<PluginInfoTypeName></PluginInfoTypeName>` MSBuild property._ | ||
### Default Build Configuration | ||
### Publish to Thunderstore | ||
|
||
This Sdks provides out-of-the-box configuration of your project, ensuring proper Release builds when publishing, and default `TargetFramework` optimizations. | ||
> _In order to create a Thunderstore Package, the Sdk requires that `icon.png`, `CHANGELOG.md` and `README.md` files exist at the project root._ | ||
### Use Modern Language Features | ||
In the `.csproj` of the plugin, provide the metadata used to generate a `manifest.json` for publishing: | ||
```xml | ||
<Project Sdk="LethalCompany.Plugin.Sdk/1.0.0"> | ||
|
||
<PropertyGroup> | ||
<!-- ... --> | ||
|
||
This Sdk adds a reference to [PolySharp](https://github.com/Sergio0694/PolySharp) to your project, allowing you to use the latest language and compiler features, like `ImplicitUsings`, `Nullable`, and more (enabled by default). | ||
<Description>My example plugin!</Description> | ||
<ThunderId>ExamplePlugin</ThunderId> | ||
<ThunderWebsiteUrl>https://example.com</ThunderWebsiteUrl> | ||
<Version>1.0.0</Version> | ||
</PropertyGroup> | ||
|
||
### Game Library References | ||
<ItemGroup> | ||
<ThunderDependency Include="ExampleTeam-OtherPlugin-1.0.0" /> | ||
</ItemGroup> | ||
|
||
This Sdk adds a reference to [`LethalAPI.GameLibs`](https://github.com/dhkatz/LethalAPI.GameLibs) to your project, allowing capabilities like CI/CD. | ||
</Project> | ||
``` | ||
|
||
### Publish to Thunderstore | ||
The following `manifest.json` would be generated for the example metadata: | ||
```json | ||
{ | ||
"name": "ExamplePlugin", | ||
"dependecies": ["BepInEx-BepInExPack-5.4.2100", "ExampleTeam-OtherPlugin-1.0.0"], | ||
"description": "My example plugin!", | ||
"version_number": "1.0.0", | ||
"website_url": "https://example.com" | ||
} | ||
``` | ||
|
||
This Sdk provides custom build properties for generating a `manifest.json`, and extends publish targets to generate an archive from project assets that's ready for upload to Thunderstore. | ||
To create a Thunderstore package, use `dotnet publish`: | ||
``` | ||
$ dotnet publish | ||
MSBuild version 17.8.3+195e7f5a3 for .NET | ||
Determining projects to restore... | ||
All projects are up-to-date for restore. | ||
ExamplePlugin -> .\bin\Debug\netstandard2.1\ExamplePlugin.dll | ||
ExamplePlugin -> .\bin\Debug\netstandard2.1\publish\ | ||
Zipping directory ".\bin\Debug\netstandard2.1\publish\" to ".\bin\Debug\netstandard2.1\ExamplePlugin-1.0.0.zi | ||
p". | ||
``` | ||
|
||
### Code Analysis | ||
#### Specify Thunderstore Dependencies | ||
|
||
This Sdk adds a reference to the [NETAnalyzers](https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/overview?tabs=net-8) to your project, and sets the default analysis level to `latest-recommended`. | ||
To specify Thunderstore dependencies in the generated `manifest.json`, use the `ThunderDependency` item: | ||
```xml | ||
<ItemGroup> | ||
<ThunderDependency Include="ExampleTeam-ExamplePlugin-1.0.0" /> | ||
</ItemGroup> | ||
``` | ||
|
||
Additional analyzers, such as [`BepInEx.Analyzers`](https://github.com/BepInEx/BepInEx.Analyzers), are also included. | ||
> _The Sdk specifies a default `ThunderDependency` on `BepInExPack`, specifying one yourself is unnecessary._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<Import Project="..\src\build\LethalCompany.Plugin.Sdk.props" /> | ||
<Project> | ||
<Import Project="..\src\Sdk\Sdk.props" /> | ||
|
||
<PropertyGroup> | ||
<Title>Plugin SDK Sample</Title> | ||
<Description>Test plugin generated using the LC-Plugin-Sdk</Description> | ||
<Description>Test plugin generated using the LethalCompany.Plugin.Sdk</Description> | ||
<PluginId>cryptoc1.lethalcompany.sdksample</PluginId> | ||
<PluginInfoTypeName>SamplePluginInfo</PluginInfoTypeName> | ||
<ThunderId>LC_SDK_SAMPLE</ThunderId> | ||
<TargetFramework>netstandard2.1</TargetFramework> | ||
<Version>1.0.0</Version> | ||
|
||
<NoWarn>$(NoWarn);CA1822;</NoWarn> | ||
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile> | ||
</PropertyGroup> | ||
|
||
<Import Project="..\src\build\LethalCompany.Plugin.Sdk.targets" /> | ||
<Import Project="..\src\Sdk\Sdk.targets" /> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters