Skip to content

Commit

Permalink
- remove BepInEx.Core dep, use ThunderDependency instead
Browse files Browse the repository at this point in the history
- use .tasks file for registering MSBuild tasks
- improve logging of successful plugin restorations
  • Loading branch information
Cryptoc1 committed Jan 4, 2024
1 parent fa904ee commit 0cfca2f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 369 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $ 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/{LATEST-VERSION}"`, and replace any existing content with metadata about the plugin:
```xml
<Project Sdk="LethalCompany.Plugin.Sdk/1.1.0">
<Project Sdk="LethalCompany.Plugin.Sdk/...">

<PropertyGroup>
<Title>Plugin Example</Title>
Expand Down
12 changes: 5 additions & 7 deletions src/RestorePluginDependencies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ private bool TryRestore(PluginCache cache, PluginDependencyGraph graph, [NotNull

foreach (var restoration in restorations)
{
if (restoration is PluginRestoration.Skipped)
if (restoration is PluginRestoration.Success success)
{
Log.LogMessage($"Skipped restoring '{restoration.Moniker}', it already exists in the cache.");
Log.LogMessage(success is PluginRestoration.Skipped
? $"Skipped restoring '{restoration.Moniker}', it already exists in the cache."
: $"Restored '{success.Moniker}' to '{success.Path}'.");

continue;
}

Expand All @@ -183,11 +186,6 @@ private bool TryRestore(PluginCache cache, PluginDependencyGraph graph, [NotNull
restored = false;
continue;
}

if (restoration is PluginRestoration.Success success)
{
Log.LogMessage($"Restored '{success.Moniker}' to '{success.Path}'.");
}
}

return restored;
Expand Down
9 changes: 6 additions & 3 deletions src/Sdk/Sdk.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" Condition=" '$(MicrosoftCommonPropsHasBeenImported)' != 'true' "/>

<ItemDefinitionGroup>
Expand Down Expand Up @@ -38,7 +39,6 @@

<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.0.8" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.4.21" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0" PrivateAssets="all" />
<PackageReference Include="LethalAPI.GameLibs" Version="45.1.0" PrivateAssets="all" ExcludeAssets="all" GeneratePathProperty="true" NoWarn="NU1701" />
<PackageReference Include="PolySharp" Version="1.14.1" PrivateAssets="all" />
Expand All @@ -48,7 +48,10 @@
</ItemGroup>

<ItemGroup>
<ThunderDependency Include="BepInEx-BepInExPack" Version="5.4.2100" ExcludeAssets="*" />
<ThunderDependency Include="BepInEx-BepInExPack" Version="5.4.2100">
<ExcludeAssets>**\BepInEx\core\0Harmony20.dll</ExcludeAssets>
<IncludeAssets>**\BepInEx\core\*.dll</IncludeAssets>
</ThunderDependency>
</ItemGroup>

<PropertyGroup Condition=" '$(GITHUB_ACTIONS)' == 'true' ">
Expand Down
12 changes: 1 addition & 11 deletions src/Sdk/Sdk.targets
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />

<PropertyGroup Condition=" '$(PluginSdkAssembly)' == '' ">
<PluginSdkAssemblyDir Condition=" '$(PluginSdkAssemblyDir)' == '' ">..\build\</PluginSdkAssemblyDir>
<PluginSdkAssembly Condition=" '$(MSBuildRuntimeType)' == 'Core' ">$(PluginSdkAssemblyDir)net8.0\LethalCompany.Plugin.Sdk.dll</PluginSdkAssembly>
<PluginSdkAssembly Condition=" '$(MSBuildRuntimeType)' != 'Core' ">$(PluginSdkAssemblyDir)net472\LethalCompany.Plugin.Sdk.dll</PluginSdkAssembly>
</PropertyGroup>

<UsingTask TaskName="GeneratePluginInfoCode" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="GeneratePluginManifestJson" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="ResolvePluginAssemblies" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="RestorePluginDependencies" AssemblyFile="$(PluginSdkAssembly)" />
<Import Project="Sdk.tasks" Condition=" '$(PluginSdkAssemblyHasBeenImported)' != 'true' " />

<PropertyGroup>
<PluginManagerDataDir Condition=" '$(PluginManagerDataDir)' == '' AND '$(PluginManager)' == 'r2modman' ">$(AppData)\r2modmanPlus-local\LethalCompany\</PluginManagerDataDir>
Expand Down
18 changes: 18 additions & 0 deletions src/Sdk/Sdk.tasks
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<PluginSdkAssemblyHasBeenImported>true</PluginSdkAssemblyHasBeenImported>
</PropertyGroup>

<PropertyGroup Condition=" '$(PluginSdkAssembly)' == '' ">
<PluginSdkAssemblyDir Condition=" '$(PluginSdkAssemblyDir)' == '' ">..\build\</PluginSdkAssemblyDir>
<PluginSdkAssembly Condition=" '$(MSBuildRuntimeType)' == 'Core' ">$(PluginSdkAssemblyDir)net8.0\LethalCompany.Plugin.Sdk.dll</PluginSdkAssembly>
<PluginSdkAssembly Condition=" '$(MSBuildRuntimeType)' != 'Core' ">$(PluginSdkAssemblyDir)net472\LethalCompany.Plugin.Sdk.dll</PluginSdkAssembly>
</PropertyGroup>

<UsingTask TaskName="LethalCompany.Plugin.Sdk.GeneratePluginInfoCode" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="LethalCompany.Plugin.Sdk.GeneratePluginManifestJson" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="LethalCompany.Plugin.Sdk.ResolvePluginAssemblies" AssemblyFile="$(PluginSdkAssembly)" />
<UsingTask TaskName="LethalCompany.Plugin.Sdk.RestorePluginDependencies" AssemblyFile="$(PluginSdkAssembly)" />

</Project>
2 changes: 1 addition & 1 deletion test/LethalCompany.SdkSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</ItemGroup>

<PropertyGroup>
<PluginSdkAssemblyDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\src\bin\Debug\'))</PluginSdkAssemblyDir>
<PluginSdkAssemblyDir>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\src\bin\$(Configuration)\'))</PluginSdkAssemblyDir>
</PropertyGroup>

<Import Project="..\src\Sdk\Sdk.targets" />
Expand Down
Loading

0 comments on commit 0cfca2f

Please sign in to comment.