Skip to content

Commit

Permalink
Merge pull request #364 from kzu/main
Browse files Browse the repository at this point in the history
Provide a dotnet global tool version of ilrepack
  • Loading branch information
KirillOsenkov authored Jul 26, 2024
2 parents 7abb7fa + ab66d9c commit 15aef03
Show file tree
Hide file tree
Showing 14 changed files with 413 additions and 44 deletions.
131 changes: 131 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
# Builds and runs tests in all three supported OSes
# Pushes CI feed if secrets.SLEET_CONNECTION is provided

name: build
on:
workflow_dispatch:
push:
branches: [ main, dev, 'dev/*', 'feature/*', 'rel/*' ]
paths-ignore:
- changelog.md
- code-of-conduct.md
- security.md
- support.md
- readme.md
pull_request:
types: [opened, synchronize, reopened]

env:
DOTNET_NOLOGO: true
Configuration: Release
PackageOutputPath: ${{ github.workspace }}/bin
VersionPrefix: 42.42.${{ github.run_number }}
VersionLabel: ${{ github.ref }}

defaults:
run:
shell: bash

jobs:
build:
runs-on: "windows-latest"
steps:
- name: 🤘 checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: ⚙ msbuild
uses: microsoft/setup-msbuild@v2

- name: 🙏 build
shell: pwsh
run: msbuild /r /m /bl

- name: 🧪 test
run: dotnet test --no-build -l trx

- name: 🗎 trx
if: always()
run: |
dotnet tool install -g dotnet-trx
trx
- name: 📦 pack
run: |
dotnet pack --no-build ILRepack/ILRepack.csproj
dotnet pack --no-build ILRepackTool/ILRepackTool.csproj
- name: ⬆️ upload
if: success()
uses: actions/upload-artifact@v3
with:
name: pkg
path: bin/*

- name: 🐛 logs
uses: actions/upload-artifact@v3
if: runner.debug && always()
with:
name: logs
path: '*.binlog'

- name: 🚀 sleet
env:
SLEET_CONNECTION: ${{ secrets.SLEET_CONNECTION }}
if: env.SLEET_CONNECTION != ''
run: |
dotnet tool install -g --version 4.0.18 sleet
sleet push bin --config none -f --verbose -p "SLEET_FEED_CONTAINER=nuget" -p "SLEET_FEED_CONNECTIONSTRING=${{ secrets.SLEET_CONNECTION }}" -p "SLEET_FEED_TYPE=azure" || echo "No packages found"
test-tool:
name: test-${{ matrix.os }}
needs: build
runs-on: ${{ matrix.os }}
defaults:
run:
shell: pwsh
strategy:
matrix:
os: [ 'windows-latest', 'ubuntu-latest', 'macOS-latest' ]
steps:
- name: 🤘 checkout
uses: actions/checkout@v4

- name: ⬇️ artifacts
uses: actions/download-artifact@v3
with:
name: pkg
path: bin

- name: ⚙ install
working-directory: bin
run: dotnet tool update -g dotnet-ilrepack --prerelease --add-source .

- name: 🧪 run
run: |
ilrepack --version
- name: 📦 ilrepack
shell: pwsh
working-directory: ILRepack.IntegrationTests/Scenarios/AnalyzerWithDependencies
run: |
dotnet build -c:Release -p:MergeAnalyzerAssemblies=false
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Abstractions.dll | Should -Be $true
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll | Should -Be $true
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Logging.dll | Should -Be $true
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Tokens.dll | Should -Be $true
test-path bin/Release/netstandard2.0/System.Text.Encoding.CodePages.dll | Should -Be $true
test-path bin/Release/netstandard2.0/System.Text.Encodings.Web.dll | Should -Be $true
test-path bin/Release/netstandard2.0/System.Text.Json.dll | Should -Be $true
# ensure the same assemblies are not present when ilrepack global tool is run
dotnet build -c:Release -p:MergeAnalyzerAssemblies=true
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Abstractions.dll | Should -Be $false
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.JsonWebTokens.dll | Should -Be $false
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Logging.dll | Should -Be $false
test-path bin/Release/netstandard2.0/Microsoft.IdentityModel.Tokens.dll | Should -Be $false
test-path bin/Release/netstandard2.0/System.Text.Encoding.CodePages.dll | Should -Be $false
test-path bin/Release/netstandard2.0/System.Text.Encodings.Web.dll | Should -Be $false
test-path bin/Release/netstandard2.0/System.Text.Json.dll | Should -Be $false
50 changes: 50 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Builds a final release version and pushes to nuget.org
# whenever a release is published.
# Requires: secrets.NUGET_API_KEY

name: publish
on:
release:
types: [prereleased, released]

env:
DOTNET_NOLOGO: true
Configuration: Release
PackageOutputPath: ${{ github.workspace }}/bin
VersionLabel: ${{ github.ref }}

jobs:
publish:
runs-on: windows-latest
steps:
- name: 🤘 checkout
uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- name: ⚙ msbuild
uses: microsoft/setup-msbuild@v2

- name: 🙏 build
run: msbuild /r /m /bl

- name: 🧪 test
run: dotnet test --no-build -l trx

- name: 🗎 trx
if: always()
run: |
dotnet tool install -g dotnet-trx
trx
- name: 📦 pack
run: |
dotnet pack --no-build ILRepack/ILRepack.csproj
dotnet pack --no-build ILRepackTool/ILRepackTool.csproj
- name: 🚀 nuget
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
if: env.NUGET_API_KEY != ''
run: dotnet nuget push ./bin/*.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }} --skip-duplicate
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ _NCrunch*
*.ncrunchproject
*.sln.cache
*.DotSettings
/.vs
.vs
/.idea
*.binlog
23 changes: 23 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,27 @@
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>

<PropertyGroup Label="Version">
<VersionPrefix Condition="$(VersionPrefix) == ''">42.42.42</VersionPrefix>
</PropertyGroup>

<PropertyGroup Label="Version" Condition="$(VersionLabel) != ''">
<_VersionLabel>$(VersionLabel.Replace('refs/heads/', ''))</_VersionLabel>
<_VersionLabel>$(_VersionLabel.Replace('refs/tags/v', ''))</_VersionLabel>

<!-- For PRs, we just need a fixed package version numbered after the PR # itself, so remove the commits # at the end -->
<_VersionLabel Condition="$(_VersionLabel.Contains('refs/pull/'))">$(VersionLabel.TrimEnd('.0123456789'))</_VersionLabel>
<!-- Next replace the prefix for simply 'pr', so we end up with 'pr99/merge' by default -->
<_VersionLabel>$(_VersionLabel.Replace('refs/pull/', 'pr'))</_VersionLabel>
<!-- Remove the /merge now, if present -->
<_VersionLabel>$(_VersionLabel.Replace('/merge', ''))</_VersionLabel>
<!-- Finally sanitize the branch with dashes, so we can build path-separated branches, like rel/v1.0.0 or feature/foo -->
<_VersionLabel>$(_VersionLabel.Replace('/', '-'))</_VersionLabel>

<!-- Set sanitized version to the actual version suffix used in build/pack -->
<VersionSuffix Condition="!$(VersionLabel.Contains('refs/tags/'))">$(_VersionLabel)</VersionSuffix>
<!-- Special case for tags, the label is actually the version. Backs compat since passed-in value overrides MSBuild-set one -->
<Version Condition="$(VersionLabel.Contains('refs/tags/'))">$(_VersionLabel)</Version>
</PropertyGroup>

</Project>
15 changes: 8 additions & 7 deletions ILRepack.IntegrationTests/ILRepack.IntegrationTests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<DebugType>embedded</DebugType>
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
</PropertyGroup>
Expand All @@ -26,13 +26,14 @@
<ProjectReference Include="..\ILRepack\ILRepack.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="fasterflect" Version="2.1.3" />
<PackageReference Include="FSharp.Core" Version="4.0.0.1" />
<PackageReference Include="SharpZipLib" Version="1.3.3"/>
<PackageReference Include="Moq" Version="4.2.1409.1722" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="Rx-Main" Version="2.2.5" />
<PackageReference Include="fasterflect" Version="3.0.0" />
<PackageReference Include="FSharp.Core" Version="8.0.300" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="SourceLink" Version="1.1.0" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Reactive" Version="6.0.1" />
<PackageReference Include="System.Resources.Extensions" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<MergeAnalyzerAssemblies Condition="$(Configuration) == 'Release'">true</MergeAnalyzerAssemblies>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.10.0" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.6.2" />
</ItemGroup>

<Target Name="ILRepack" AfterTargets="CoreCompile" BeforeTargets="CopyFilesToOutputDirectory"
Inputs="@(IntermediateAssembly -&gt; '%(FullPath)')"
Outputs="$(IntermediateOutputPath)ilrepack.txt"
Returns="@(MergedAssemblies)"
Condition="Exists(@(IntermediateAssembly -&gt; '%(FullPath)')) And '$(MergeAnalyzerAssemblies)' == 'true'">
<ItemGroup>
<ReferenceCopyLocalAssemblies Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.dll'
And !$([MSBuild]::ValueOrDefault('%(FileName)', '').EndsWith('.resources', StringComparison.OrdinalIgnoreCase))" />
<MergedAssemblies Include="@(ReferenceCopyLocalAssemblies)" Condition="
!$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('Microsoft.CodeAnalysis', StringComparison.OrdinalIgnoreCase)) And
!$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('Microsoft.CSharp', StringComparison.OrdinalIgnoreCase)) And
!$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('System.', StringComparison.OrdinalIgnoreCase))"
/>
<!-- Brings in System/Microsoft.IdentityModel, System.Text.Encodings.Web, System.Text.Json -->
<MergedAssemblies Include="@(ReferenceCopyLocalAssemblies)" Condition="
$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('System.IdentityModel', StringComparison.OrdinalIgnoreCase)) Or
$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('Microsoft.IdentityModel', StringComparison.OrdinalIgnoreCase)) Or
$([MSBuild]::ValueOrDefault('%(FileName)', '').StartsWith('System.Text', StringComparison.OrdinalIgnoreCase))"
/>
</ItemGroup>
<ItemGroup>
<ReferenceCopyLocalDirs Include="@(ReferenceCopyLocalPaths -&gt; '%(RootDir)%(Directory)')" />
<ReferenceCopyLocalPaths Remove="@(MergedAssemblies)" />
<LibDir Include="@(ReferenceCopyLocalDirs -&gt; Distinct())" />
</ItemGroup>
<PropertyGroup>
<AbsoluteAssemblyOriginatorKeyFile Condition="'$(AssemblyOriginatorKeyFile)' != ''">$([System.IO.Path]::GetFullPath($([System.IO.Path]::Combine('$(MSBuildProjectDirectory)','$(AssemblyOriginatorKeyFile)'))))</AbsoluteAssemblyOriginatorKeyFile>
<ILRepackArgs Condition="'$(AbsoluteAssemblyOriginatorKeyFile)' != ''">/keyfile:"$(AbsoluteAssemblyOriginatorKeyFile)" /delaysign</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) /internalize</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) /union</ILRepackArgs>
<!-- This is needed to merge types with identical names into one, wich happens with IFluentInterface in Merq and Merq.Core (Xamarin.Messaging dependencies) -->
<ILRepackArgs>$(ILRepackArgs) @(LibDir -&gt; '/lib:"%(Identity)."', ' ')</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) /out:"@(IntermediateAssembly -&gt; '%(FullPath)')"</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) "@(IntermediateAssembly -&gt; '%(FullPath)')"</ILRepackArgs>
<ILRepackArgs>$(ILRepackArgs) @(MergedAssemblies -&gt; '"%(FullPath)"', ' ')</ILRepackArgs>
</PropertyGroup>

<!-- Run dotnet global tool version of ilrepack -->
<Exec Command='ilrepack $(ILRepackArgs)' WorkingDirectory="$(MSBuildProjectDirectory)\$(OutputPath)" StandardErrorImportance="high" IgnoreStandardErrorWarningFormat="true" StandardOutputImportance="low" ConsoleToMSBuild="true" ContinueOnError="true">
<Output TaskParameter="ConsoleOutput" PropertyName="ILRepackOutput" />
<Output TaskParameter="ExitCode" PropertyName="ExitCode" />
</Exec>
<Message Importance="high" Text="$(ILRepackOutput)" Condition="'$(ExitCode)' != '0'" />
<Delete Files="$(IntermediateOutputPath)ilrepack.txt" Condition="'$(ExitCode)' != '0'" />
<Touch AlwaysCreate="true" Files="$(IntermediateOutputPath)ilrepack.txt" Condition="'$(ExitCode)' == '0'" />
<Error Text="$(ILRepackOutput)" Condition="'$(ExitCode)' != '0' And '$(ContinueOnError)' != 'true'" />
<ItemGroup>
<MergedAssembliesToRemove Include="@(MergedAssemblies)" />
<MergedAssembliesToRemove Remove="@(ReferenceToPreserve)" />
</ItemGroup>
<Delete Files="@(MergedAssembliesToRemove -&gt; '$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" Condition="Exists('$(MSBuildProjectDirectory)\$(OutputPath)%(Filename)%(Extension)')" />
</Target>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.IdentityModel.JsonWebTokens;

namespace AnalyzerWithDependencies;

[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class SampleAnalyzer : DiagnosticAnalyzer
{
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics => [
new DiagnosticDescriptor("AWD001", "Sample analyzer", "Hello {0}", "Design", DiagnosticSeverity.Warning, isEnabledByDefault: true)];

public override void Initialize(AnalysisContext context)
{
context.EnableConcurrentExecution();
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics);

context.RegisterCompilationAction(ctx =>
{
var compilation = ctx.Compilation;
// Exercise some external dependency
var token = new JsonWebToken("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c");
var name = token.GetPayloadValue<string>("name");
var diagnostic = Diagnostic.Create(SupportedDiagnostics[0], Location.None, name);
ctx.ReportDiagnostic(diagnostic);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Exercises the dotnet-ilrepack tool instead of the ilrepack.exe

Requires the dotnet-ilrepack tool to be installed. Before compiling.
Loading

0 comments on commit 15aef03

Please sign in to comment.