Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
<SentryUploadSources>true</SentryUploadSources>
</PropertyGroup>

<!-- If running in CI and auth token is not set, disable SentryCLI completely (to avoid logging warnings). -->
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true' And '$(SENTRY_AUTH_TOKEN)' == ''">
<UseSentryCLI>false</UseSentryCLI>
</PropertyGroup>
Comment on lines -53 to -56
Copy link
Collaborator Author

@vaind vaind Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: This (and other similar cases below) is now handled by a condition in Sentry.targets property UseSentryCLI


<!--
Note: The following platform-specific properties need to be set in both Directory.Build.props and DirectoryBuild.targets.
TODO: Figure out how to consolidate to a single location.
Expand Down
1 change: 0 additions & 1 deletion benchmarks/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<!-- Never use Sentry CLI for benchmark projects. -->
<PropertyGroup>
<UseSentryCLI>false</UseSentryCLI>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
1 change: 0 additions & 1 deletion build.cmd
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
set UseSentryCLI=false
dotnet build Sentry.sln -c Release
dotnet test Sentry.sln -c Release --no-build
1 change: 0 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export UseSentryCLI=false
dotnet build Sentry.sln -c Release
dotnet test Sentry.sln -c Release --no-build
5 changes: 0 additions & 5 deletions samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<!-- Never use Sentry CLI for sample projects when building in CI. -->
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
<UseSentryCLI>false</UseSentryCLI>
</PropertyGroup>

<!--
This sets the default DSN for all sample projects. Sentry employees and contractors
can view events at https://sentry-sdks.sentry.io/projects/sentry-dotnet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<TargetFrameworks>net7.0;net8.0</TargetFrameworks>

<!-- Remove after switching to .NET 8 SDK -->
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('OSX'))">
<TargetFramework>net6.0</TargetFramework>
<PublishAot>false</PublishAot>
</PropertyGroup>
<PropertyGroup Condition="!$([MSBuild]::IsOSPlatform('OSX'))">
<TargetFramework>net7.0</TargetFramework>
<PublishAot>true</PublishAot>
<!-- AOT not supported for osx-arm64 on .NET 7 -->
<PublishAot Condition="!$([MSBuild]::IsOSPlatform('OSX')) or '$(TargetFramework)' == 'net8.0'">true</PublishAot>
</PropertyGroup>

<PropertyGroup>
Expand Down
128 changes: 84 additions & 44 deletions src/Sentry/buildTransitive/Sentry.targets
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@
<SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == ''">false</SentryUploadSymbols>
<SentryUploadSources Condition="'$(SentryUploadSources)' == ''">false</SentryUploadSources>

<!-- This property controls if the Sentry CLI is to be used at all. Setting false will disable all Sentry CLI usage. -->
<UseSentryCLI Condition="'$(UseSentryCLI)' == '' And ('$(SentryUploadSymbols)' == 'true' Or '$(SentryUploadSources)' == 'true' Or $(SentryUploadAndroidProguardMapping) == 'true')">true</UseSentryCLI>
<!-- This property controls if the Sentry CLI is to be used at all. Setting false will disable all Sentry CLI usage.
We're explicitly skipping uploads for Sentry projects (except samples) because they interfere with CLI integration test asserts. -->
<UseSentryCLI Condition="
'$(UseSentryCLI)' == ''
and ('$(SentryUploadSymbols)' == 'true' or '$(SentryUploadSources)' == 'true' or $(SentryUploadAndroidProguardMapping) == 'true')
and ('$(MSBuildProjectName)' != 'Sentry')
and (!$(MSBuildProjectName.StartsWith('Sentry.')) or '$(MSBuildProjectName)' == '$(SentryCLIIntegrationTestProject)')">true</UseSentryCLI>
</PropertyGroup>
</Target>

Expand Down Expand Up @@ -120,53 +125,88 @@

</Target>

<!-- Upload symbols to Sentry after the build. -->
<Target Name="UploadSymbolsToSentry" AfterTargets="Build;Publish" DependsOnTargets="PrepareSentryCLI"
Condition="'$(SentryUploadSymbols)' == 'true' And '$(SentryCLI)' != ''">

<Message Importance="High"
Text="Preparing to upload debug symbols to Sentry for $(MSBuildProjectName) ($(Configuration)/$(TargetFramework))" />

<ItemGroup>
<SentryCLIUploadSymbolType Include="pdb" />
<SentryCLIUploadSymbolType Include="portablepdb" />
<SentryCLIUploadSymbolType Include="dsym" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" />
<SentryCLIUploadSymbolType Include="dsym" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'" />
</ItemGroup>

<Exec Command="$(SentryCLIDebugFilesUploadCommand) @(SentryCLIUploadSymbolType -> '-t %(Identity)', ' ') $(OutputPath)" IgnoreExitCode="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>
<!-- Native AOT publishing
While '_IsPublishing' looks a bit "private", it's also OK if it suddenly stops working and this step runs anyway.
See https://github.com/dotnet/sdk/issues/26324#issuecomment-1169236993 -->
<PropertyGroup Condition="'$(PublishDir)' != '' and '$(PublishAot)' == 'true' and '$(_IsPublishing)' == 'true'">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see we already have a CI_PUBLISHING_BUILD property... I take it this doesn't work because it's only ever set by by our github actions (and we want this to work even in the context of builds on local development machines)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a transitive build target, so one that gets triggered during lib-consumer builds.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha... cunning. I had no idea we were doing that (or that it was even possible - never had a need before). Is that enabled simply by this?

<!--
Include Sentry's custom targets file in the nuget package.
This file contains targets that are invoked during the end-user's build.
The same file is included twice, so it ends up being used for both direct and transitive package references to Sentry.
-->
<ItemGroup>
<None Include="buildTransitive\Sentry.targets" Pack="true" PackagePath="buildTransitive\Sentry.targets" />
<None Include="buildTransitive\Sentry.targets" Pack="true" PackagePath="build\Sentry.targets" />
</ItemGroup>

I think that's all we need to do right (reading the docs).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that's it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and I've learned about this a couple of weeks ago myself, for the same reason :)

<SentryCLIUploadNativeAOT>true</SentryCLIUploadNativeAOT>
<SentryCLIUploadDirectory>$(PublishDir)</SentryCLIUploadDirectory>
<!-- We must run after "CopyNativeBinary" (not "Publish"),
because that is the one that actually copies native AOT symbols to the publish directory. -->
<SentryCLIUploadAfterTargets>CopyNativeBinary</SentryCLIUploadAfterTargets>
</PropertyGroup>
<ItemGroup Condition="'$(SentryCLIUploadNativeAOT)' == 'true'">
<SentryCLIUploadSymbolType Include="pdb" />
<SentryCLIUploadSymbolType Include="dsym" />
<SentryCLIUploadSymbolType Include="elf" />
</ItemGroup>

<!-- "Standard" managed build -->
<PropertyGroup Condition="'$(SentryCLIUploadNativeAOT)' != 'true'">
<SentryCLIUploadNativeAOT>false</SentryCLIUploadNativeAOT>
<SentryCLIUploadDirectory>$(OutputPath)</SentryCLIUploadDirectory>
<SentryCLIUploadAfterTargets>Build</SentryCLIUploadAfterTargets>
</PropertyGroup>
<ItemGroup Condition="'$(SentryCLIUploadNativeAOT)' != 'true'">
<SentryCLIUploadSymbolType Include="pdb" />
<SentryCLIUploadSymbolType Include="portablepdb" />
<SentryCLIUploadSymbolType Include="dsym" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'" />
<SentryCLIUploadSymbolType Include="dsym" Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'" />
</ItemGroup>

<!-- Upload symbols to Sentry after the build. -->
<Target Name="UploadDebugInfoToSentry" AfterTargets="$(SentryCLIUploadAfterTargets)" DependsOnTargets="PrepareSentryCLI"
Condition="'$(SentryCLI)' != '' and ('$(SentryUploadSymbols)' == 'true' or '$(SentryUploadSources)' == 'true')">

<!-- if (UploadSymbols && UploadSources) { -->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for those!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah they're nice although at one point I've found myself just copying a piece of a code from one if branch to the other, forgetting to actually update the relevant condition 😅

<Message Importance="High"
Condition="'$(SentryUploadSymbols)' == 'true' and '$(SentryUploadSources)' == 'true'"
Text="Preparing upload to Sentry for project '$(MSBuildProjectName)' ($(Configuration)/$(TargetFramework)): collecting debug symbols and referenced source code from $(SentryCLIUploadDirectory)" />
<Exec
Condition="'$(SentryUploadSymbols)' == 'true' and '$(SentryUploadSources)' == 'true'"
Command="$(SentryCLIDebugFilesUploadCommand) @(SentryCLIUploadSymbolType -> '-t %(Identity)', ' ') --include-sources $(SentryCLIUploadDirectory)"
IgnoreExitCode="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>
<!-- } else if (UploadSymbols && !UploadSources) { -->
<Message Importance="High"
Condition="'$(SentryUploadSymbols)' == 'true' and '$(SentryUploadSources)' != 'true'"
Text="Preparing upload to Sentry for project '$(MSBuildProjectName)' ($(Configuration)/$(TargetFramework)): collecting debug symbols from $(SentryCLIUploadDirectory)" />
<Exec
Condition="'$(SentryUploadSymbols)' == 'true' and '$(SentryUploadSources)' != 'true'"
Command="$(SentryCLIDebugFilesUploadCommand) @(SentryCLIUploadSymbolType -> '-t %(Identity)', ' ') $(SentryCLIUploadDirectory)"
IgnoreExitCode="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>
<!-- } else if (!UploadSymbols && UploadSources) { -->
<PropertyGroup>
<SentryCLIDebugInfoFile Condition="'$(NativeBinary)' != ''">$(NativeBinary)$(NativeSymbolExt)</SentryCLIDebugInfoFile>
<SentryCLIDebugInfoFile Condition="'$(NativeBinary)' == '' or !Exists('$(SentryCLIDebugInfoFile)')">@(IntermediateAssembly->'$(SentryCLIUploadDirectory)%(FileName).pdb')</SentryCLIDebugInfoFile>
<SentryCLIDebugInfoFile Condition="!Exists('$(SentryCLIDebugInfoFile)')">@(IntermediateAssembly->'$(SentryCLIUploadDirectory)%(FileName)%(Extension)')</SentryCLIDebugInfoFile>
<SentryCLIUploadSourcesDirectory>$([System.IO.Path]::GetDirectoryName('$(SentryCLIDebugInfoFile)'))</SentryCLIUploadSourcesDirectory>
</PropertyGroup>
<Message Importance="High"
Condition="'$(SentryUploadSymbols)' != 'true' and '$(SentryUploadSources)' == 'true'"
Text="Preparing upload to Sentry for project '$(MSBuildProjectName)' ($(Configuration)/$(TargetFramework)): collecting source code referenced by $(SentryCLIDebugInfoFile)" />
<Exec
Condition="'$(SentryUploadSymbols)' != 'true' and '$(SentryUploadSources)' == 'true'"
Command="&quot;$(SentryCLI)&quot; debug-files bundle-sources $(SentryCLIDebugInfoFile) " IgnoreExitCode="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>
<Warning Condition="'$(_SentryCLIExitCode)' != '0'" Text="Sentry CLI could not upload debug files." />
<Exec
Condition="'$(SentryUploadSymbols)' != 'true' and '$(SentryUploadSources)' == 'true' and '$(_SentryCLIExitCode)' == '0'"
Command="$(SentryCLIDebugFilesUploadCommand) -t sourcebundle $(SentryCLIUploadSourcesDirectory)"
IgnoreExitCode="true" ContinueOnError="WarnAndContinue">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>
<!-- } -->
<Warning Condition="'$(_SentryCLIExitCode)' != '0'" Text="Sentry CLI could not upload debug files." />

</Target>

<!-- Upload sources to Sentry after the build. -->
<Target Name="UploadSourcesToSentry" AfterTargets="Build;UploadSymbolsToSentry" DependsOnTargets="PrepareSentryCLI"
Condition="'$(SentryUploadSources)' == 'true' And '$(SentryCLI)' != ''">

<Message Importance="High" Condition="'$(SentryUploadSources)' == 'true'"
Text="Preparing to upload sources to Sentry for $(MSBuildProjectName) ($(Configuration)/$(TargetFramework))" />

<PropertyGroup>
<_SentryDebugInfoFile>@(IntermediateAssembly->'$(IntermediateOutputPath)%(FileName).pdb')</_SentryDebugInfoFile>
<_SentryDebugInfoFile Condition="!Exists('$(_SentryDebugInfoFile)')">@(IntermediateAssembly->'$(IntermediateOutputPath)%(FileName)%(Extension)')</_SentryDebugInfoFile>
<_SentrySourceBundle>@(IntermediateAssembly->'$(IntermediateOutputPath)%(FileName).src.zip')</_SentrySourceBundle>
</PropertyGroup>

<Exec Command="&quot;$(SentryCLI)&quot; debug-files bundle-sources $(_SentryDebugInfoFile)" IgnoreExitCode="true" ContinueOnError="WarnAndContinue" />
<Exec Command="$(SentryCLIDebugFilesUploadCommand) $(_SentrySourceBundle)" IgnoreExitCode="true" ContinueOnError="WarnAndContinue" Condition="Exists('$(_SentrySourceBundle)')">
<Output TaskParameter="ExitCode" PropertyName="_SentryCLIExitCode" />
</Exec>

<Warning Condition="'$(_SentryCLIExitCode)' != '0'" Text="Sentry CLI could not upload sources." />

</Target>

<!-- Upload Android Proguard mapping file to Sentry after the build. -->
<Target Name="UploadAndroidProguardMappingFileToSentry" AfterTargets="Build"
Condition="'$(SentryUploadAndroidProguardMapping)' == 'true' And '$(AndroidProguardMappingFile)' != ''">
<Target Name="UploadAndroidProguardMappingFileToSentry" AfterTargets="Build" DependsOnTargets="PrepareSentryCLI"
Condition="'$(SentryCLI)' != '' and '$(SentryUploadAndroidProguardMapping)' == 'true' And '$(AndroidProguardMappingFile)' != ''">

<Message Importance="High" Text="Preparing to upload Android Proguard mapping to Sentry for '$(MSBuildProjectName)': $(AndroidProguardMappingFile))" />

Expand Down
5 changes: 0 additions & 5 deletions test/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<!-- Never use Sentry CLI for test projects. -->
<PropertyGroup>
<UseSentryCLI>false</UseSentryCLI>
</PropertyGroup>

<!--
Workaround for Verify issue with scrubbing when running in Rider on Windows.
Ensures that the volume label is upper cased ("C:" instead of "c:"), which is read
Expand Down
Loading