sentry-dotnet
sentry-dotnet copied to clipboard
build: Fix reference to Sentry.SourceGenerators
supersedes #4290
git clean -fdx
dotnet pack ./src/Sentry/Sentry.csproj --configuration Debug
before:
error : Could not find a part of the path './sentry-dotnet/src/Sentry.SourceGenerators/bin/Release/netstandard2.0'
after:
Build succeeded
#skip-changelog
@sentry review
On it! We are reviewing the PR and will provide feedback shortly.
PR Description
This pull request aims to improve the packaging of the Sentry.SourceGenerators project as a Roslyn analyzer within the main Sentry NuGet package. The goal is to ensure that the source generators are correctly included and function as expected during the build process of projects that consume the Sentry SDK.
Click to see more
Key Technical Changes
The primary technical change is the replacement of a direct file inclusion (of the compiled Sentry.SourceGenerators.dll) with an MSBuild target-based approach. This involves using a <ProjectReference> to the Sentry.SourceGenerators project and a custom MSBuild target (_SentryPackAnalyzers) to build the source generators project and include its output assembly in the analyzers/dotnet/cs directory of the NuGet package. The SetTargetFramework attribute on the ProjectReference ensures the generator is built for netstandard2.0.
Architecture Decisions
The architectural decision is to leverage MSBuild's extensibility to dynamically build and package the analyzer. This approach avoids hardcoding file paths and ensures that the analyzer is always built with the correct configuration for the target environment. This also allows for better control over the build process and potential customization in the future.
Dependencies and Interactions
This change introduces a dependency on the MSBuild system to correctly build and package the analyzer. It interacts with the NuGet packaging process by adding the analyzer assembly to the appropriate directory within the package. It depends on the Sentry.SourceGenerators project being buildable and producing a valid analyzer assembly.
Risk Considerations
Potential risks include issues with the MSBuild target not correctly building or packaging the analyzer, leading to projects consuming the Sentry SDK not benefiting from the source generators. There's also a risk that changes to the Sentry.SourceGenerators project could break the build process if the MSBuild target is not updated accordingly. The SetTargetFramework attribute on the ProjectReference is unconventional and might cause issues with some MSBuild versions.
Notable Implementation Details
The _SentryPackAnalyzers target is defined to run before the _GetPackageFiles target, ensuring that the analyzer is built and included in the package before the package is created. The SentryAnalyzersPack metadata on the ProjectReference is used to identify the project that should be packaged as an analyzer. The Visible="false" attribute on the <None Include> element prevents the analyzer assembly from being included in the project's output directory.
@Flash0ver it'd be great to pick this back up - I still run into this issue when trying to run the integration tests locally.