Skip to content

Commit

Permalink
improved+documented plugin staging
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptoc1 committed Dec 19, 2023
1 parent 3736408 commit 85533c1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public sealed class SamplePlugin : BaseUnityPlugin
```
> _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._
> _The name of the generated class can be changed using the `<PluginInfoTypeName />` MSBuild property._

### Publish to Thunderstore

Expand Down Expand Up @@ -89,6 +90,17 @@ MSBuild version 17.8.3+195e7f5a3 for .NET
p".
```

#### Staging Plugins

"Staging" a plugin refers to the process of publishing a plugin directly to a local Thunderstore profile.

This can be done by setting two additional properties when using `dotnet publish`:
```bash
dotnet publish -p:StagePlugin=true -p:PluginStagingProfile="..."
```

> _It is recommended to set the `<PluginStagingProfile />` MSBuild property in a `.csproj.user` file._
#### Specify Thunderstore Dependencies

To specify Thunderstore dependencies in the generated `manifest.json`, use the `ThunderDependency` item:
Expand Down
11 changes: 8 additions & 3 deletions src/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static class $(PluginInfoTypeName)
<_PublishDir>$(PublishDir)</_PublishDir>
<PublishDir>$(OutputPath)publish\</PublishDir>

<_PluginProfileDir Condition=" '$(PluginStagingProfile)' != '' ">$(AppData)\Thunderstore Mod Manager\DataFolder\LethalCompany\profiles\$(PluginStagingProfile)</_PluginProfileDir>
<PluginStagingDir Condition=" '$(PluginStagingProfile)' != '' ">$(_PluginProfileDir)\BepInEx\plugins\$(ThunderId)</PluginStagingDir>

<_PluginPackage>$(_PublishDir)\$(ThunderId)-$(PluginVersion).zip</_PluginPackage>

<!-- NOTE: a custom output path was NOT specified, place the archive in 'bin\', rather than 'bin\publish\' (can't place archive in the folder being archived) -->
Expand All @@ -93,18 +96,20 @@ public static class $(PluginInfoTypeName)
</Target>

<Target Name="PublishPlugin" AfterTargets="Publish">
<Warning Code="LC001" Text="Plugin was not built in Release mode, users may experience an impact to their performance!" Condition=" '$(Configuration)' != 'Release' AND '$(PublishPluginSuppressConfigurationWarning)' != 'true' AND '$(StagePlugin)' != 'true' " />
<Warning Code="LC001" Text="Plugin was not built in Release mode, users may experience an impact to their performance!" Condition=" '$(Configuration)' != 'Release' AND '$(StagePlugin)' != 'true' " />

<!-- NOTE: we don't need this, BepInEx has it's own runtime semantics for resolving deps! -->
<!-- NOTE: we don't need this, BepInEx has it's own semantics for resolving runtime deps! -->
<Delete Files="$(PublishDir)\$(AssemblyName).deps.json" />

<ItemGroup>
<_PluginFiles Include="$(PublishDir)\**\*.*" Exclude="$(PublishDir)\$(AssemblyName).deps.json" />
<_PluginFiles Remove="$(PublishDir)\$(AssemblyName).deps.json" />

<_PluginStagingDirFiles Include="$(PluginStagingDir)\**.*" />
</ItemGroup>

<Error Code="LC002" Text="Cannot Stage Plugin, PluginStagingProfile directory '$(_PluginProfileDir)' does not exist." Condition=" '$(StagePlugin)' == 'true' AND !Exists('$(_PluginProfileDir)') " />
<MakeDir Directories="$(PluginStagingDir)" />

<Delete Files="@(_PluginStagingDirFiles)" Condition=" '$(StagePlugin)' == 'true' " />
<Copy SourceFiles="@(_PluginFiles)" DestinationFiles="@(_PluginFiles -> '$(PluginStagingDir)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="true" Condition=" '$(StagePlugin)' == 'true' " />

Expand Down

0 comments on commit 85533c1

Please sign in to comment.