Skip to content

Commit

Permalink
Fix issue with Sentry CLI msbuild properties (#2119)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjohnsonpint authored Jan 17, 2023
1 parent 3593c35 commit 48b2f5a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix issue with Sentry CLI msbuild properties ([#2119](https://github.com/getsentry/sentry-dotnet/pull/2119))

## 3.26.0

### Features
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
These are needed because we use project references in this solution.
In an app that uses our nuget packages, they will come through the nuget packages automatically.
-->
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\buildTransitive\Sentry.props" />
<Import Project="$(MSBuildThisFileDirectory)src\Sentry\buildTransitive\Sentry.targets" />
<Import Project="$(MSBuildThisFileDirectory)src\Sentry.Bindings.Cocoa\buildTransitive\Sentry.Bindings.Cocoa.targets"
Condition="'$(OutputType)' == 'Exe' And ('$(TargetPlatformIdentifier)' == 'ios' Or '$(TargetPlatformIdentifier)' == 'maccatalyst')" />

Expand Down
4 changes: 2 additions & 2 deletions src/Sentry/Sentry.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
</ItemGroup>

<ItemGroup>
<None Include="buildTransitive\Sentry.props" Pack="true" PackagePath="buildTransitive\Sentry.props" />
<None Include="buildTransitive\Sentry.props" Pack="true" PackagePath="build\Sentry.props" />
<None Include="buildTransitive\Sentry.targets" Pack="true" PackagePath="buildTransitive\Sentry.targets" />
<None Include="buildTransitive\Sentry.targets" Pack="true" PackagePath="build\Sentry.targets" />
</ItemGroup>

<!-- Download the Sentry CLI during the restore phase. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<SentryAttributesFile>Sentry.Attributes$(MSBuildProjectExtension.Replace('proj', ''))</SentryAttributesFile>
</PropertyGroup>

<Target Name="WriteSentryAttributes"
Condition="$(Language) == 'VB' or $(Language) == 'C#' or $(Language) == 'F#'"
BeforeTargets="BeforeCompile;CoreCompile"
Expand All @@ -19,44 +21,38 @@
<!-- Ensure not part of Compile, as a workaround for https://github.com/dotnet/sdk/issues/114 -->
<Compile Remove="$(SentryAttributesFilePath)" />
</ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(SentryAttributes)"
Language="$(Language)"
OutputFile="$(SentryAttributesFilePath)">
<Output Condition="$(Language) != 'F#'"
TaskParameter="OutputFile"
ItemName="Compile" />
<Output Condition="$(Language) == 'F#'"
TaskParameter="OutputFile"
ItemName="CompileBefore" />
<Output TaskParameter="OutputFile"
ItemName="FileWrites" />
<WriteCodeFragment AssemblyAttributes="@(SentryAttributes)" Language="$(Language)" OutputFile="$(SentryAttributesFilePath)">
<Output Condition="$(Language) != 'F#'" TaskParameter="OutputFile" ItemName="Compile" />
<Output Condition="$(Language) == 'F#'" TaskParameter="OutputFile" ItemName="CompileBefore" />
<Output TaskParameter="OutputFile" ItemName="FileWrites" />
</WriteCodeFragment>
</Target>

<PropertyGroup>
<!-- Defaults for Sentry CLI are set here. Any of these properties can be set in the application to override the defaults. -->
<SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == '' And '$(Configuration)' == 'Release' And '$(DebugType)' != 'embedded'">true</SentryUploadSymbols>
<!-- Additional properties can go here. For example, SentryCreateNewRelease, etc. -->
<Target Name="CheckSentryCLI" AfterTargets="DispatchToInnerBuilds;AfterBuild">
<PropertyGroup>
<!-- This property controls whether symbols are to be sent to Sentry. -->
<SentryUploadSymbols Condition="'$(SentryUploadSymbols)' == '' And '$(Configuration)' == 'Release' And '$(DebugType)' != 'embedded'">true</SentryUploadSymbols>

<!-- 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')">true</UseSentryCLI>
<!-- 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')">true</UseSentryCLI>
</PropertyGroup>
</Target>

<!--
The Sentry configuration can be set manually in MSBuild properties if desired.
Otherwise the default configuration will be used, as reported by "sentry-cli info".
The defaults can be set either via config file, or environment variables, per: https://docs.sentry.io/product/cli/configuration/
-->
<SentryCLIOptions Condition="'$(SentryApiKey)' != ''">$(SentryCLIOptions) --api-key $(SentryApiKey)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryAuthToken)' != ''">$(SentryCLIOptions) --auth-token $(SentryAuthToken)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryUrl)' != ''">$(SentryCLIOptions) --url $(SentryUrl)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryOrg)' != ''">$(SentryCLIOptions) --org '$(SentryOrg)'</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryProject)' != ''">$(SentryCLIOptions) --project '$(SentryProject)'</SentryCLIOptions>
</PropertyGroup>
<Target Name="PrepareSentryCLI" AfterTargets="CheckSentryCLI" Condition="'$(UseSentryCLI)' == 'true'">
<PropertyGroup>
<!--
The Sentry configuration can be set manually in MSBuild properties if desired.
Otherwise the default configuration will be used, as reported by "sentry-cli info".
The defaults can be set either via config file, or environment variables, per: https://docs.sentry.io/product/cli/configuration/
-->
<SentryCLIOptions Condition="'$(SentryApiKey)' != ''">$(SentryCLIOptions) --api-key $(SentryApiKey)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryAuthToken)' != ''">$(SentryCLIOptions) --auth-token $(SentryAuthToken)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryUrl)' != ''">$(SentryCLIOptions) --url $(SentryUrl)</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryOrg)' != ''">$(SentryCLIOptions) --org '$(SentryOrg)'</SentryCLIOptions>
<SentryCLIOptions Condition="'$(SentryProject)' != ''">$(SentryCLIOptions) --project '$(SentryProject)'</SentryCLIOptions>

<Target Name="_PrepareSentryCLI" AfterTargets="DispatchToInnerBuilds;AfterBuild" Condition="'$(UseSentryCLI)' == 'true'">
<!-- Sentry CLI comes from the Sentry Nuget package when installed. -->
<PropertyGroup Condition="'$(SentryCLIDirectory)' == ''">
<SentryCLIDirectory Condition="'$(PkgSentry)' != ''">$(PkgSentry)\tools\</SentryCLIDirectory>
<!-- Sentry CLI comes from the Sentry Nuget package when installed. -->
<SentryCLIDirectory Condition="'$(SentryCLIDirectory)' == '' And '$(PkgSentry)' != ''">$(PkgSentry)\tools\</SentryCLIDirectory>
</PropertyGroup>

<!--
Expand Down Expand Up @@ -99,7 +95,7 @@
</Target>

<!-- Upload symbols (and any other debug information files) to Sentry after the build. -->
<Target Name="UploadSymbolsToSentry" AfterTargets="AfterBuild" DependsOnTargets="_PrepareSentryCLI" Condition="'$(SentryUploadSymbols)' == 'true' And '$(SentryCLI)' != ''">
<Target Name="UploadSymbolsToSentry" AfterTargets="AfterBuild" DependsOnTargets="PrepareSentryCLI" Condition="'$(SentryUploadSymbols)' == 'true' And '$(SentryCLI)' != ''">
<Message Importance="High" Text="Preparing to upload debug symbols to Sentry for $(MSBuildProjectName) ($(Configuration)/$(TargetFramework))" />
<Exec Command="'$(SentryCLI)' upload-dif $(SentryCLIOptions) '$(IntermediateOutputPath)'" />
</Target>
Expand Down

0 comments on commit 48b2f5a

Please sign in to comment.