Skip to content

Commit 78b6a03

Browse files
Merge pull request #129 from getsentry/fix/cs1701-warnings
fix: Silence CS1701/CS1702 warnings from Add-Type on PowerShell Core
2 parents 4355d10 + 707daed commit 78b6a03

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

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+
### Fixes
6+
7+
- Silence CS1701/CS1702 warnings emitted by `Add-Type` when importing the module on PowerShell hosts whose runtime `System.Runtime` version differs from the one `Sentry.dll` was compiled against ([#129](https://github.com/getsentry/sentry-powershell/pull/129))
8+
59
### Features
610

711
- Add `Write-SentryLog` cmdlet, a native PowerShell API for sending structured logs (Sentry Logs) ([#131](https://github.com/getsentry/sentry-powershell/pull/131))

modules/Sentry/Sentry.psm1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,16 @@ $moduleInfo = Import-PowerShellDataFile (Join-Path (Split-Path -Parent $MyInvoca
55
. "$privateDir/Get-SentryAssembliesDirectory.ps1"
66
$sentryDllPath = (Join-Path (Get-SentryAssembliesDirectory) 'Sentry.dll')
77

8-
Add-Type -TypeDefinition (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw) -ReferencedAssemblies $sentryDllPath -Debug:$false
8+
$addTypeParams = @{
9+
TypeDefinition = (Get-Content "$privateDir/SentryEventProcessor.cs" -Raw)
10+
ReferencedAssemblies = $sentryDllPath
11+
Debug = $false
12+
}
13+
# -CompilerOptions is PS Core only; suppress CS1701/CS1702 (harmless binding-redirect noise) when available.
14+
if ($PSEdition -eq 'Core') {
15+
$addTypeParams['CompilerOptions'] = '/nowarn:CS1701;CS1702'
16+
}
17+
Add-Type @addTypeParams
918
. "$privateDir/SentryEventProcessor.ps1"
1019

1120
Get-ChildItem $publicDir -Filter '*.ps1' | ForEach-Object {

0 commit comments

Comments
 (0)