Skip to content

Commit

Permalink
Ensure dotnet-ilrepack is installed before IL merging
Browse files Browse the repository at this point in the history
This simplifies consumption and avoids having to create custom CI build steps to install the right tool.

If the PR to include this global tool in the main ILRepack distribution is merged (see gluck/il-repack#364), we can remove the --add-source and --prerelease switches.
  • Loading branch information
kzu committed Jul 8, 2024
1 parent 9905644 commit f5c7cc1
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions samples/dotnet/SponsorLink.targets
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,20 @@ partial class SponsorLink
</ItemGroup>
</Target>

<Target Name="EnsureILRepack" BeforeTargets="ILRepack" Condition="'$(MergeAnalyzerAssemblies)' == 'true'">
<Exec Command="ilrepack --version" StandardErrorImportance="high" StandardOutputImportance="low" ConsoleToMSBuild="true" IgnoreExitCode="true" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput" />
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
</Exec>
<Message Importance="high" Text="Using installed dotnet-ilrepack v$(ILRepackOutput)" Condition="$(ExitCode) == '0'" />
<Exec Command="dotnet tool install -g dotnet-ilrepack --prerelease --add-source https://kzu.blob.core.windows.net/nuget/index.json"
Condition="$(ExitCode) != '0'" />
<Exec Command="ilrepack --version" Condition="$(ExitCode) != '0'" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackInstalledOutput" />
</Exec>
<Message Importance="high" Text="Installed dotnet-ilrepack v$(ILRepackInstalledOutput)" Condition="$(ExitCode) != '0'" />
</Target>

<Target Name="ILRepack" AfterTargets="CoreCompile" BeforeTargets="CopyFilesToOutputDirectory"
Inputs="@(IntermediateAssembly -&gt; '%(FullPath)')"
Outputs="$(IntermediateOutputPath)ilrepack.txt"
Expand Down

0 comments on commit f5c7cc1

Please sign in to comment.