Skip to content

Commit 6b17e2c

Browse files
Use Sentry CLI after build to upload symbols (#2107)
1 parent 6e1cdd6 commit 6b17e2c

16 files changed

+146
-21
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ docs/docfx.zip
2323
mono_crash.*.json
2424
test_output/
2525
test/**/*.apk
26+
/tools/

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+
- Use Sentry CLI after build to upload symbols ([#2107](https://github.com/getsentry/sentry-dotnet/pull/2107))
8+
59
### Fixes
610

711
- Logging info instead of warning when skipping debug images ([#2101](https://github.com/getsentry/sentry-dotnet/pull/2101))

Directory.Build.props

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@
5656
<Compile Include="$(MSBuildThisFileDirectory)GlobalUsings.cs" />
5757
</ItemGroup>
5858

59+
<!-- Set the version and local path for Sentry CLI (downloaded in the restore phase of Sentry.csproj) -->
60+
<PropertyGroup Condition="'$(SolutionName)' != 'Sentry.Unity'">
61+
<SentryCLIVersion>2.11.0</SentryCLIVersion>
62+
<SentryCLIDirectory>$(MSBuildThisFileDirectory)tools\sentry-cli\$(SentryCLIVersion)\</SentryCLIDirectory>
63+
</PropertyGroup>
64+
5965
</Project>

Directory.Build.targets

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@
4747
</Target>
4848

4949
<!--
50-
This is needed because we use project references in this solution.
51-
In an app that uses our nuget packages, it will come through the nuget package automatically.
50+
These are needed because we use project references in this solution.
51+
In an app that uses our nuget packages, they will come through the nuget packages automatically.
5252
-->
53+
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\buildTransitive\Sentry.props" />
5354
<Import Project="$(MSBuildThisFileDirectory)src\Sentry.Bindings.Cocoa\buildTransitive\Sentry.Bindings.Cocoa.targets"
54-
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />
55+
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />
5556

5657
</Project>

src/Sentry/Sentry.csproj

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,42 @@
6767
<None Include="buildTransitive\Sentry.props" Pack="true" PackagePath="build\Sentry.props" />
6868
</ItemGroup>
6969

70+
<!-- Download the Sentry CLI during the restore phase. -->
71+
<Target Name="DownloadSentryCLI" BeforeTargets="CollectPackageReferences" Condition="'$(SentryCLIDirectory)' != ''">
72+
73+
<!--
74+
Hashes are from https://release-registry.services.sentry.io/apps/sentry-cli/latest
75+
Update with each new version.
76+
-->
77+
<ItemGroup>
78+
<SentryCLIDownload Include="sentry-cli-Darwin-arm64" FileHash="fbefb40a8e5ce29f82e0f7195e84f569dbeaaae07cdc1f983f5f3418fd9a376d" />
79+
<SentryCLIDownload Include="sentry-cli-Darwin-x86_64" FileHash="d55ee5636d12bd193a4f526ab426e6af6273bec5bc2dc22e81dc8357d6e039eb" />
80+
<SentryCLIDownload Include="sentry-cli-Linux-aarch64" FileHash="c62c5c1259307611e78af4f24a4c30162cff8adb0f021d363b307c42cded5c70" />
81+
<SentryCLIDownload Include="sentry-cli-Linux-i686" FileHash="25c5e7e6d978d1e66bc26c9e4282633135a318ed0ac36cb73b4fa58f59fcb089" />
82+
<SentryCLIDownload Include="sentry-cli-Linux-x86_64" FileHash="bc8f5f223fa688b3ad963c60a729f02aa8f5b17525de66fb3abf86800977ff6e" />
83+
<SentryCLIDownload Include="sentry-cli-Windows-i686.exe" FileHash="2bb96fc94ea749e24cd607f48750b121572a3fb4b3f9499f63a996f83c56ef2b" />
84+
<SentryCLIDownload Include="sentry-cli-Windows-x86_64.exe" FileHash="7b70536177419dcd2fdb2c823422290abfe25180ffa3beae000fb3c9b1473c1f"/>
85+
</ItemGroup>
86+
87+
<!-- Download the files -->
88+
<DownloadFile
89+
SourceUrl="https://downloads.sentry-cdn.com/sentry-cli/$(SentryCLIVersion)/%(SentryCLIDownload.Identity)"
90+
DestinationFolder="$(SentryCLIDirectory)"
91+
Condition="!Exists('$(SentryCLIDirectory)%(Identity)')"
92+
Retries="3">
93+
<Output TaskParameter="DownloadedFile" ItemName="SentryCLIDownloadedFile" />
94+
</DownloadFile>
95+
96+
<!-- Build will fail if any downloaded files don't match the expected hash. -->
97+
<VerifyFileHash File="$(SentryCLIDirectory)%(SentryCLIDownload.Identity)" Hash="%(FileHash)" />
98+
99+
<!-- Set executable permissions for local usage. -->
100+
<Exec Command="chmod +x $(SentryCLIDirectory)*" Condition="!$([MSBuild]::IsOSPlatform('Windows'))" />
101+
</Target>
102+
103+
<!-- Bundle the Sentry CLI into the Sentry Nuget package. -->
104+
<ItemGroup Condition="'$(SentryCLIDirectory)' != ''">
105+
<None Include="$(SentryCLIDirectory)**" Pack="true" PackagePath="tools\" />
106+
</ItemGroup>
107+
70108
</Project>

src/Sentry/buildTransitive/Sentry.props

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,76 @@
3232
ItemName="FileWrites" />
3333
</WriteCodeFragment>
3434
</Target>
35+
36+
<PropertyGroup>
37+
<!-- Defaults for Sentry CLI are set here. Any of these properties can be set in the application to override the defaults. -->
38+
<SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == '' And '$(Configuration)' == 'Release' And '$(DebugType)' != 'embedded'">true</SentryUploadSymbols>
39+
<!-- Additional properties can go here. For example, SentryCreateNewRelease, etc. -->
40+
41+
<!-- This property controls if the Sentry CLI is to be used at all. Setting false will disable all Sentry CLI usage. -->
42+
<UseSentryCLI Condition="'$(UseSentryCLI)' == '' And ('$(SentryUploadSymbols)' == 'true')">true</UseSentryCLI>
43+
44+
<!--
45+
The Sentry configuration can be set manually in MSBuild properties if desired.
46+
Otherwise the default configuration will be used, as reported by "sentry-cli info".
47+
The defaults can be set either via config file, or environment variables, per: https://docs.sentry.io/product/cli/configuration/
48+
-->
49+
<SentryCLIOptions Condition="'$(SentryApiKey)' != ''">$(SentryCLIOptions) --api-key $(SentryApiKey)</SentryCLIOptions>
50+
<SentryCLIOptions Condition="'$(SentryAuthToken)' != ''">$(SentryCLIOptions) --auth-token $(SentryAuthToken)</SentryCLIOptions>
51+
<SentryCLIOptions Condition="'$(SentryUrl)' != ''">$(SentryCLIOptions) --url $(SentryUrl)</SentryCLIOptions>
52+
<SentryCLIOptions Condition="'$(SentryOrg)' != ''">$(SentryCLIOptions) --org '$(SentryOrg)'</SentryCLIOptions>
53+
<SentryCLIOptions Condition="'$(SentryProject)' != ''">$(SentryCLIOptions) --project '$(SentryProject)'</SentryCLIOptions>
54+
</PropertyGroup>
55+
56+
<Target Name="_PrepareSentryCLI" AfterTargets="DispatchToInnerBuilds;AfterBuild" Condition="'$(UseSentryCLI)' == 'true'">
57+
<!-- Sentry CLI comes from the Sentry Nuget package when installed. -->
58+
<PropertyGroup Condition="'$(SentryCLIDirectory)' == ''">
59+
<SentryCLIDirectory Condition="'$(PkgSentry)' != ''">$(PkgSentry)\tools\</SentryCLIDirectory>
60+
</PropertyGroup>
61+
62+
<!--
63+
Choose the correct Sentry CLI executable depending on OS platform and architecture.
64+
For Windows on Arm64, we'll use the X64 build for now (which should run via emulation).
65+
Switch to a Windows Arm64 build when available. See https://github.com/getsentry/sentry-cli/issues/1426
66+
-->
67+
<PropertyGroup Condition="'$(SentryCLI)' == '' And '$(SentryCLIDirectory)' != ''">
68+
<_OSArchitecture>$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture)</_OSArchitecture>
69+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('OSX')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Darwin-arm64</SentryCLI>
70+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('OSX')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Darwin-x86_64</SentryCLI>
71+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Linux-aarch64</SentryCLI>
72+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'X86'">$(SentryCLIDirectory)sentry-cli-Linux-i686</SentryCLI>
73+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Linux')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Linux-x86_64</SentryCLI>
74+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'Arm64'">$(SentryCLIDirectory)sentry-cli-Windows-x86_64</SentryCLI>
75+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'X86'">$(SentryCLIDirectory)sentry-cli-Windows-i686</SentryCLI>
76+
<SentryCLI Condition="$([MSBuild]::IsOSPlatform('Windows')) And $(_OSArchitecture) == 'X64'">$(SentryCLIDirectory)sentry-cli-Windows-x86_64</SentryCLI>
77+
<SentryCLI Condition="!Exists('$(SentryCLI)')"/>
78+
</PropertyGroup>
79+
80+
<PropertyGroup>
81+
<_SentryCLIInfoOptions Condition="'$(SentryOrg)' != '' And '$(SentryProject)' != ''">--no-defaults</_SentryCLIInfoOptions>
82+
</PropertyGroup>
83+
<Exec Command="'$(SentryCLI)' info $(_SentryCLIInfoOptions)" Condition="'$(SentryCLI)' != ''" IgnoreExitCode="true" ConsoleToMsBuild="true" StandardOutputImportance="Low">
84+
<Output TaskParameter="ExitCode" PropertyName="SentryCLIExitCode" />
85+
<Output TaskParameter="ConsoleOutput" PropertyName="SentryCLIOutput" />
86+
</Exec>
87+
88+
<PropertyGroup Condition="'$(SentryCLIExitCode)' != '0'">
89+
<_SentryCLIRequestFailed Condition="$(SentryCLIOutput.Contains('API request failed'))">true</_SentryCLIRequestFailed>
90+
</PropertyGroup>
91+
<Warning Condition="'$(_SentryCLIRequestFailed)' != ''"
92+
Text="Sentry API request failed. Either the authentication info is invalid, or the Sentry server could not be reached." />
93+
94+
<Message Importance="High" Condition="'$(SentryCLIExitCode)' != '0' And '$(_SentryCLIRequestFailed)' == ''"
95+
Text="The Sentry CLI is not fully configured with authentication, organization, and project." />
96+
<PropertyGroup Condition="'$(SentryCLIExitCode)' != '0'">
97+
<SentryCLI />
98+
</PropertyGroup>
99+
</Target>
100+
101+
<!-- Upload symbols (and any other debug information files) to Sentry after the build. -->
102+
<Target Name="UploadSymbolsToSentry" AfterTargets="AfterBuild" DependsOnTargets="_PrepareSentryCLI" Condition="'$(SentryUploadSymbols)' == 'true' And '$(SentryCLI)' != ''">
103+
<Message Importance="High" Text="Preparing to upload debug symbols to Sentry for $(MSBuildProjectName) ($(Configuration)/$(TargetFramework))" />
104+
<Exec Command="'$(SentryCLI)' upload-dif $(SentryCLIOptions) '$(IntermediateOutputPath)'" />
105+
</Target>
106+
35107
</Project>

test/Sentry.NLog.Tests/IntegrationTests.Simple.Core3_1.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Stacktrace: {
3232
Frames: [
3333
{,
34-
"filename": ".../IntegrationTests.verify.cs",
34+
"filename": "IntegrationTests.verify.cs",
3535
"function": "Task IntegrationTests.Simple()",
3636
"lineno": 47,
3737
"colno": 17,

test/Sentry.NLog.Tests/IntegrationTests.Simple.DotNet6_0.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Stacktrace: {
3232
Frames: [
3333
{,
34-
"filename": ".../IntegrationTests.verify.cs",
34+
"filename": "IntegrationTests.verify.cs",
3535
"function": "Task IntegrationTests.Simple()",
3636
"lineno": 47,
3737
"colno": 17,

test/Sentry.NLog.Tests/IntegrationTests.Simple.DotNet7_0.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Stacktrace: {
3232
Frames: [
3333
{,
34-
"filename": ".../IntegrationTests.verify.cs",
34+
"filename": "IntegrationTests.verify.cs",
3535
"function": "Task IntegrationTests.Simple()",
3636
"lineno": 47,
3737
"colno": 17,

test/Sentry.NLog.Tests/IntegrationTests.Simple.Net4_8.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
Stacktrace: {
3232
Frames: [
3333
{,
34-
"filename": ".../IntegrationTests.verify.cs",
34+
"filename": "IntegrationTests.verify.cs",
3535
"function": "Task IntegrationTests.Simple()",
3636
"lineno": 47,
3737
"colno": 17,

test/Sentry.Serilog.Tests/IntegrationTests.Simple.Core3_1.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
Stacktrace: {
162162
Frames: [
163163
{,
164-
"filename": ".../IntegrationTests.verify.cs",
164+
"filename": "IntegrationTests.verify.cs",
165165
"function": "Task IntegrationTests.Simple()",
166166
"lineno": 46,
167167
"colno": 17,

test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet6_0.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
Stacktrace: {
162162
Frames: [
163163
{,
164-
"filename": ".../IntegrationTests.verify.cs",
164+
"filename": "IntegrationTests.verify.cs",
165165
"function": "Task IntegrationTests.Simple()",
166166
"lineno": 46,
167167
"colno": 17,

test/Sentry.Serilog.Tests/IntegrationTests.Simple.DotNet7_0.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
Stacktrace: {
162162
Frames: [
163163
{,
164-
"filename": ".../IntegrationTests.verify.cs",
164+
"filename": "IntegrationTests.verify.cs",
165165
"function": "Task IntegrationTests.Simple()",
166166
"lineno": 46,
167167
"colno": 17,

test/Sentry.Serilog.Tests/IntegrationTests.Simple.Net4_8.verified.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161
Stacktrace: {
162162
Frames: [
163163
{,
164-
"filename": ".../IntegrationTests.verify.cs",
164+
"filename": "IntegrationTests.verify.cs",
165165
"function": "Task IntegrationTests.Simple()",
166166
"lineno": 46,
167167
"colno": 17,

test/Sentry.Testing/ApiExtensions.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#if !__MOBILE__
2+
using System.Runtime.Versioning;
23
using PublicApiGenerator;
34

45
namespace Sentry.Testing;
@@ -9,20 +10,24 @@ public static Task CheckApproval(this Assembly assembly, [CallerFilePath] string
910
{
1011
var generatorOptions = new ApiGeneratorOptions
1112
{
13+
ExcludeAttributes = new []
14+
{
15+
typeof(AssemblyVersionAttribute).FullName,
16+
typeof(AssemblyFileVersionAttribute).FullName,
17+
typeof(AssemblyInformationalVersionAttribute).FullName,
18+
typeof(AssemblyMetadataAttribute).FullName,
19+
typeof(InternalsVisibleToAttribute).FullName,
20+
typeof(TargetFrameworkAttribute).FullName
21+
},
1222
WhitelistedNamespacePrefixes = new[] { "Sentry", "Microsoft" }
1323
};
1424
var apiText = assembly.GeneratePublicApi(generatorOptions);
25+
26+
// ReSharper disable once ExplicitCallerInfoArgument
1527
return Verify(apiText, null, filePath)
1628
.AutoVerify(includeBuildServer: false)
1729
.UniqueForTargetFrameworkAndVersion()
18-
.ScrubEmptyLines()
19-
.ScrubLines(l =>
20-
l.StartsWith("[assembly: System.Runtime.CompilerServices.InternalsVisibleTo(") ||
21-
l.StartsWith("[assembly: AssemblyVersion(") ||
22-
l.StartsWith("[assembly: System.Runtime.Versioning.TargetFramework(") ||
23-
l.StartsWith("[assembly: AssemblyFileVersion(") ||
24-
l.StartsWith("[assembly: AssemblyInformationalVersion(") ||
25-
l.StartsWith("[assembly: System.Reflection.AssemblyMetadata("));
30+
.ScrubEmptyLines();
2631
}
2732
}
2833
#endif

test/Sentry.Tests/Sentry.Tests.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@
1414
<ProjectReference Include="..\Sentry.Testing.CrashableApp\Sentry.Testing.CrashableApp.csproj" />
1515
</ItemGroup>
1616

17-
<Import Project="..\..\src\Sentry\buildTransitive\Sentry.props" />
18-
1917
</Project>

0 commit comments

Comments
 (0)