Skip to content

Commit

Permalink
[MTGOSDK] Merge reference assemblies
Browse files Browse the repository at this point in the history
Merge all reference assemblies into the MTGOSDK library, avoiding distributing a separate MTGOSDK.Ref assembly.
  • Loading branch information
Qonfused committed Apr 13, 2024
1 parent ae0ce1b commit 3771558
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 52 deletions.
1 change: 0 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

<PropertyGroup>
<UseFullSDKPaths>true</UseFullSDKPaths>
<RestoreUseStaticGraphEvaluation>true</RestoreUseStaticGraphEvaluation>
</PropertyGroup>

</Project>
53 changes: 15 additions & 38 deletions MTGOSDK.MSBuild/build/MTGOSDK.MSBuild.targets
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,30 @@
<Output TaskParameter="OutputPath" PropertyName="_MTGOSDK_Refs" />
</GenerateReferenceAssemblies>

<!-- TODO: Verify the output reference assemblies w/ ILVerify -->
<!-- Add the reference assembly path to the assembly search paths -->
<PropertyGroup Condition="'$(UseRef)' == 'true'">
<AssemblySearchPaths>$(AssemblySearchPaths);$(_MTGOSDK_Refs)</AssemblySearchPaths>
</PropertyGroup>

<!-- Notify if the task has finished or skipped generating assemblies -->
<Message Text="MTGOSDK.MSBuild: Updated reference assemblies for MTGO version $(MTGOVersion)"
Importance="high"
Condition="'$(HasSkipped)' != 'true'" />
<Message Text="MTGOSDK.MSBuild: Reference assemblies are located at $(_MTGOSDK_Refs)"
Importance="high"
Condition="'$(HasSkipped)' != 'true'" />
</Target>

<!-- Merge reference assemblies into MTGOSDK.Ref -->
<Message Text="MTGOSDK.MSBuild: Merging reference assemblies into MTGOSDK.Ref"
Importance="high"
Condition="!Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />
<ItemGroup>
<Flags Include="/ndebug" />
<Flags Include="/allowDup" />
<Flags Include="/lib=$(_MTGOSDK_Refs)" />
<Flags Include="/out=$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll" />
</ItemGroup>
<PropertyGroup>
<ILMergeAssemblies>@(ReferenceAssemblies-> '%(Filename)%(Extension)', ' ')</ILMergeAssemblies>
<ILMergeFlags>@(Flags-> '%(Identity)', ' ')</ILMergeFlags>
<ILMergeCommand>$(ILMergeConsolePath) $(ILMergeAssemblies) $(ILMergeFlags)</ILMergeCommand>
</PropertyGroup>
<Exec Command="$(ILMergeConsolePath) $(ILMergeAssemblies) $(ILMergeFlags)"
Condition="!Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />

<!-- Remove all other reference assemblies in the reference directory -->
<ItemGroup>
<CachedReferenceAssemblies Include="$(_MTGOSDK_Refs)\*.*"
Exclude="$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll" />
</ItemGroup>
<Delete Files="@(CachedReferenceAssemblies)"
Condition="Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />

<!-- Include MTGOSDK.Ref in the search path of a consuming project -->
<Target Name="ResolveReferenceAssemblies"
AfterTargets="ResolveAssemblyReferences"
BeforeTargets="CoreCompile"
DependsOnTargets="GenerateReferenceAssemblies">
<ItemGroup>
<Reference Include="$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll"
Condition="Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />
<!-- Filter reference paths for those pointing to reference assemblies -->
<ReferenceAssemblies
Include="@(ReferenceCopyLocalPaths)"
Condition="$([System.String]::Copy(%(FullPath)).Contains($(_MTGOSDK_Refs)))" />
</ItemGroup>

<!-- Notify if the task has skipped generating reference assemblies -->
<Message Text="MTGOSDK.MSBuild: Finished bootstrapping MTGOSDK reference assemblies."
Importance="high"
Condition="Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />
<Message Text="MTGOSDK.MSBuild: Failed to bootstrap MTGOSDK reference assemblies."
Importance="high"
Condition="!Exists('$(_MTGOSDK_Refs)\MTGOSDK.Ref.dll')" />
</Target>

</Project>
40 changes: 37 additions & 3 deletions MTGOSDK/MTGOSDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,24 @@
Version="4.7.0" />
<PackageReference Include="Microsoft.Diagnostics.Runtime"
Version="3.1.512801" />
<PackageReference Include="Meziantou.Polyfill"
Version="1.0.37"
Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<PackageReference Include="ImpromptuInterface"
Version="8.0.4" />
<PackageReference Include="Newtonsoft.Json"
Version="13.0.3" />
<ProjectReference Include="..\MTGOSDK.Win32\MTGOSDK.Win32.csproj" />
<!-- Compatibility layers for .netstandard-2.0 -->
<PackageReference Include="Meziantou.Polyfill"
Version="1.0.37"
Condition="'$(TargetFramework)' == 'netstandard2.0'" />
<!-- Build-time dependencies for MTGOSDK.MSBuild -->
<PackageReference Include="ILRepack"
Version="2.0.30"
PrivateAssets="all"
Condition="'$(TargetFramework)' != 'netstandard2.0'" />
<PackageReference Include="ILRepack.Lib.MSBuild.Task"
Version="2.0.29"
PrivateAssets="all"
Condition="'$(TargetFramework)' != 'netstandard2.0'" />
</ItemGroup>

<!-- For builds used by the ScubaDiver assembly, exclude compiling the API -->
Expand Down Expand Up @@ -70,4 +80,28 @@
</ItemGroup>
</Target>

<!-- Merge the main assembly with any copied reference assemblies -->
<Target Name="MergeReferenceAssemblies"
AfterTargets="AfterBuild"
Condition="'$(TargetFramework)' != 'netstandard2.0'">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)\$(AssemblyName).dll" />
<InputAssemblies Include="@(ReferenceAssemblies -> '$(OutputPath)%(Filename).dll')" />
</ItemGroup>

<ILRepack
LibraryPath="$(OutputPath)"
OutputFile="$(OutputPath)\$(AssemblyName).dll"
InputAssemblies="@(InputAssemblies)"
Parallel="true"
Condition="Exists('%(InputAssemblies.Identity)')" />

<!-- Delete all copied reference assemblies in the output directory -->
<Delete Files="@(InputAssemblies)"
Condition="'%(Filename)' != '$(AssemblyName)'" />

<Message Text="MTGOSDK.MSBuild: Finished merging MTGOSDK reference assemblies."
Importance="high" />
</Target>

</Project>
20 changes: 10 additions & 10 deletions MTGOSDK/MTGOSDK.ref.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<UseRef>true</UseRef>
</PropertyGroup>

<ItemGroup Condition="'$(UseRef)' == 'true'">
<ItemGroup>
<!--
Add a `ProjectReference` to ensure that the task is built before being
called in a consuming project. This is necessary because the task assembly
Expand All @@ -25,19 +25,19 @@
We optionally disable copying reference assemblies to the output directory
when specifying `Private="false"`. This tells the compiler that the GAC
will provide the assemblies instead. We do this to only use the reference
assemblies for compilation, and not include them as part of the package.
will provide the assemblies instead, and to only use the reference
assemblies for compilation and not include them as part of the package.
Instead, consumers of the SDK will generate their own reference assemblies
using transitive build targets provided by the `MTGOSDK.MSBuild` project.
-->
<ReferenceAssemblies Include="Core.dll" />
<ReferenceAssemblies Include="FlsClient.dll" />
<ReferenceAssemblies Include="MTGOEnumStruct.dll" />
<ReferenceAssemblies Include="WotC.MtGO.Client.Common.dll" />
<ReferenceAssemblies Include="WotC.MtGO.Client.Model.Chat.dll" />
<ReferenceAssemblies Include="WotC.MtGO.Client.Model.Core.dll" />
<ReferenceAssemblies Include="WotC.MtGO.Client.Model.Reference.dll" />
<Reference Include="Core" Private="$(UseRef)" />
<Reference Include="FlsClient" Private="$(UseRef)" />
<Reference Include="MTGOEnumStruct" Private="$(UseRef)" />
<Reference Include="WotC.MtGO.Client.Common" Private="$(UseRef)" />
<Reference Include="WotC.MtGO.Client.Model.Chat" Private="$(UseRef)" />
<Reference Include="WotC.MtGO.Client.Model.Core" Private="$(UseRef)" />
<Reference Include="WotC.MtGO.Client.Model.Reference" Private="$(UseRef)" />
</ItemGroup>

<!--
Expand Down
12 changes: 12 additions & 0 deletions MTGOSDK/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,18 @@
}
},
"net8.0-windows7.0": {
"ILRepack": {
"type": "Direct",
"requested": "[2.0.30, )",
"resolved": "2.0.30",
"contentHash": "QanDNA1Y+Qd6uH9OzgRl9vRZrgd8ee2MO93fO8B35Mo5mK4Q8WaZsgHUPq/umLTFimI3nNO6wwbPgjBB6sBwiQ=="
},
"ILRepack.Lib.MSBuild.Task": {
"type": "Direct",
"requested": "[2.0.29, )",
"resolved": "2.0.29",
"contentHash": "kCrpMEA3mLfox1wOpPiAIEG0tQcWV+fNR2LBV4XklvT8xClwj16Z/H/FsyR+pqPgEfJIiINi0Oiwb5pglb8IJA=="
},
"ImpromptuInterface": {
"type": "Direct",
"requested": "[8.0.4, )",
Expand Down

0 comments on commit 3771558

Please sign in to comment.