Skip to content

Commit 5b4f08f

Browse files
authored
fix: dependency resolution via assembly alias for .NET Standard 2.1 (#2726)
1 parent c7f86ab commit 5b4f08f

39 files changed

Lines changed: 1302 additions & 27 deletions

.github/workflows/build.yml

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,10 @@ jobs:
126126
run: docker exec unity dotnet build -c Release -v:d
127127

128128
- name: Install assemblyalias
129-
run: docker exec unity dotnet tool install --global Alias --version 0.4.3 --allow-roll-forward
129+
run: docker exec unity dotnet tool install --global Sentry.AssemblyAlias --version 0.5.0 --allow-roll-forward
130130

131-
- name: Alias editor assemblies
132-
run: docker exec unity /home/gh/.dotnet/tools/assemblyalias --target-directory "package-dev/Editor" --internalize --prefix "Sentry." --assemblies-to-alias "Microsoft*;Mono.Cecil*"
133-
134-
- name: Alias runtime assemblies
135-
run: docker exec unity /home/gh/.dotnet/tools/assemblyalias --target-directory "package-dev/Runtime" --internalize --prefix "Sentry." --assemblies-to-alias "Microsoft*;System*"
131+
- name: Alias assemblies
132+
run: docker exec unity pwsh scripts/alias-assemblies.ps1 -AssemblyAlias /home/gh/.dotnet/tools/assemblyalias
136133

137134
- name: Package for release
138135
run: |
@@ -147,6 +144,16 @@ jobs:
147144
path: |
148145
package-release.zip
149146
147+
- name: Build DependencyConflict package
148+
run: docker exec unity dotnet build test/Scripts.Integration.Test/DependencyConflictPackage
149+
150+
- name: Upload DependencyConflict package
151+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
152+
with:
153+
name: dependency-conflict-package
154+
if-no-files-found: error
155+
path: test/Scripts.Integration.Test/DependencyConflictPackage/DependencyConflict
156+
150157
- name: Run Unity tests (playmode)
151158
run: docker exec unity dotnet msbuild /t:UnityPlayModeTest /p:Configuration=Release /p:OutDir=other test/Sentry.Unity.Tests
152159

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,15 @@ jobs:
211211
- name: Add Sentry to the project
212212
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
213213

214+
- name: Download DependencyConflict package
215+
uses: ./.github/actions/wait-for-artifact
216+
with:
217+
name: dependency-conflict-package
218+
path: dependency-conflict-package
219+
220+
- name: Add DependencyConflict to the project
221+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
222+
214223
- name: Configure Sentry
215224
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform "$env:BUILD_PLATFORM"
216225
env:

.github/workflows/test-build-android.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,15 @@ jobs:
7676
- name: Add Sentry to the project
7777
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
7878

79+
- name: Download DependencyConflict package
80+
uses: ./.github/actions/wait-for-artifact
81+
with:
82+
name: dependency-conflict-package
83+
path: dependency-conflict-package
84+
85+
- name: Add DependencyConflict to the project
86+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
87+
7988
- name: Configure Sentry
8089
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform "Android"
8190
env:

.github/workflows/test-build-ios.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ jobs:
9595
- name: Add Sentry to the project
9696
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
9797

98+
- name: Download DependencyConflict package
99+
uses: ./.github/actions/wait-for-artifact
100+
with:
101+
name: dependency-conflict-package
102+
path: dependency-conflict-package
103+
104+
- name: Add DependencyConflict to the project
105+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
106+
98107
- name: Configure Sentry
99108
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform "$env:BUILD_PLATFORM"
100109
env:

.github/workflows/test-build-linux.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ jobs:
8787
- name: Add Sentry to the project
8888
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
8989

90+
- name: Download DependencyConflict package
91+
uses: ./.github/actions/wait-for-artifact
92+
with:
93+
name: dependency-conflict-package
94+
path: dependency-conflict-package
95+
96+
- name: Add DependencyConflict to the project
97+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
98+
9099
- name: Configure Sentry
91100
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform Linux
92101
env:

.github/workflows/test-build-macos.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ jobs:
8282
- name: Add Sentry to the project
8383
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
8484

85+
- name: Download DependencyConflict package
86+
uses: ./.github/actions/wait-for-artifact
87+
with:
88+
name: dependency-conflict-package
89+
path: dependency-conflict-package
90+
91+
- name: Add DependencyConflict to the project
92+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
93+
8594
- name: Configure Sentry
8695
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform MacOS
8796
env:

.github/workflows/test-build-windows.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ jobs:
8282
- name: Add Sentry to the project
8383
run: ./test/Scripts.Integration.Test/add-sentry.ps1 -UnityPath "$env:UNITY_PATH" -PackagePath "test-package-release"
8484

85+
- name: Download DependencyConflict package
86+
uses: ./.github/actions/wait-for-artifact
87+
with:
88+
name: dependency-conflict-package
89+
path: dependency-conflict-package
90+
91+
- name: Add DependencyConflict to the project
92+
run: ./test/Scripts.Integration.Test/add-dependency-conflict.ps1 -PackagePath "dependency-conflict-package"
93+
8594
- name: Configure Sentry
8695
run: ./test/Scripts.Integration.Test/configure-sentry.ps1 -UnityPath "$env:UNITY_PATH" -Platform Windows
8796
env:

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ package-dev/**/TestSentryOptions.json
3232
package-dev/Tests/Editor/TestFiles/
3333
package-dev/Plugins/*/Sentry/crashpad_handler*
3434

35+
# DependencyConflict integration-test fixture: the DLLs are rebuilt fresh in CI
36+
# (and locally) from DependencyConflictPackage.csproj. Only the hand-authored Unity
37+
# metadata (.meta, asmdef, package.json) is tracked.
38+
test/Scripts.Integration.Test/DependencyConflictPackage/DependencyConflict/Runtime/*.dll
39+
test/Scripts.Integration.Test/DependencyConflictPackage/DependencyConflict/Runtime/*.pdb
40+
test/Scripts.Integration.Test/DependencyConflictPackage/DependencyConflict/Runtime/*.xml
41+
test/Scripts.Integration.Test/DependencyConflictPackage/obj/
42+
test/Scripts.Integration.Test/DependencyConflictPackage/bin/
43+
3544
# Download cache for native SDKs
3645
modules/sentry-native-ndk
3746

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Updated the dependency resolution within the SDK. This enables .NET Standard 2.1 both for building the SDK from source and for setting the Api Compatibility Level in the Player Settings in your project. The assembly aliasing was originally intended to prevent dependency conflicts the SDK might introduce by deeply renaming its bundled dependencies. However, this prevented Unity from resolving these dependencies at build time, creating ambiguity for certain types. To resolve this, the SDK now excludes `System.Buffers`, `System.Memory`, `System.Numerics.Vectors`, and `System.Threading.Tasks.Extensions` from being aliased, letting the Unity build pipeline handle them. ([#2726](https://github.com/getsentry/sentry-unity/pull/2726))
8+
59
### Dependencies
610

711
- Bump Native SDK from v0.15.1 to v0.15.2 ([#2728](https://github.com/getsentry/sentry-unity/pull/2728))

CLAUDE.md

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ Downloads prebuilt native SDKs from CI artifacts or releases:
218218

219219
### Assembly Aliasing
220220

221-
Prevents symbol conflicts with user dependencies using `assemblyalias` tool:
221+
Prevents symbol conflicts with user dependencies using `assemblyalias` tool. The
222+
invocation (alias patterns + the BCL exclude list) lives in one place,
223+
`scripts/alias-assemblies.ps1`, which `repack.ps1` and CI (`build.yml`) both call:
222224

223-
```bash
224-
pwsh scripts/build-and-alias.ps1
225-
```
226-
227-
- Runtime assemblies: `Microsoft*`, `System*` → prefixed with `Sentry.`
225+
- Runtime assemblies: `Microsoft*`, `System*` → prefixed with `Sentry.` (excluding the
226+
BCL facades Unity's unityaot profile already provides — see the script's comment)
228227
- Editor assemblies: `Microsoft*`, `Mono.Cecil*` → prefixed with `Sentry.`
229228

230229
### Package Structure
@@ -249,7 +248,7 @@ Scripts involved:
249248

250249
- `scripts/pack.ps1` - Creates the release package
251250
- `scripts/repack.ps1` - Full preparation pipeline
252-
- `scripts/build-and-alias.ps1` - Build with assembly aliasing
251+
- `scripts/alias-assemblies.ps1` - Single source of truth for the assembly-aliasing invocation
253252

254253
### Package Validation
255254

@@ -611,6 +610,26 @@ Located in `test/Scripts.Integration.Test/`:
611610
| `build-project.ps1` | Builds for target platform |
612611
| `measure-build-size.ps1` | Compares build size with/without SDK |
613612
| `integration-test.ps1` | Full local integration test |
613+
| `add-dependency-conflict.ps1` | Adds the DependencyConflict alias stress-test package |
614+
615+
### Assembly Aliasing Regression Test (`DependencyConflict`)
616+
617+
`test/Scripts.Integration.Test/DependencyConflictPackage/` is a committed fixture that
618+
stress-tests the SDK's assembly aliasing. It is a tiny UPM package shipping
619+
**plain, unaliased** `System.*`/`Microsoft.*` assemblies at versions that differ
620+
from the ones the SDK ships aliased in `package-dev`. Both packages are installed
621+
into the same integration test project; `IntegrationTester.cs` calls into it on
622+
startup (logging `"Dependencies say hi"`), forcing the unaliased assemblies to be
623+
linked alongside Sentry's aliased copies.
624+
625+
- The DLLs are built in `build.yml` (it has the pinned .NET SDK) and uploaded as
626+
the `dependency-conflict-package` artifact; integration jobs download it and run
627+
`add-dependency-conflict.ps1` to embed it in the test project.
628+
- Only the Unity metadata (`.meta`, asmdef, `package.json`) is committed;
629+
`DependencyConflict/Runtime/*.dll` is gitignored and rebuilt via
630+
`dotnet build test/Scripts.Integration.Test/DependencyConflictPackage`.
631+
- **A red integration build is the regression signal** — if aliasing breaks, the
632+
duplicate assemblies collide and the project no longer builds.
614633

615634
### Local Integration Testing
616635

0 commit comments

Comments
 (0)