-
-
Notifications
You must be signed in to change notification settings - Fork 220
chore: Fix reference to Sentry.SourceGenerators #4290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The current reference is very brittle: - It assumes the Sentry.SourceGenerators project has already been built - It assumes a release build - It will break if the TFM ever changes or in a multi-targeting scenario This breaks integration tests when these are run locally (since not all of the above assumptions hold up when running these locally). #skip-changelog
src/Sentry/Sentry.csproj
Outdated
Pack="true" | ||
PackagePath="analyzers/dotnet/cs" | ||
Visible="false" /> | ||
<ProjectReference Include="..\Sentry.SourceGenerators\Sentry.SourceGenerators.csproj" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling that this won't work as expected.
I don't think we are packing Sentry.SourceGenerators.dll
to the expected PackagePath.
Unfortunately, the NuGetPackageExplorer is Windows-only.
So I can't test it right away.
We need either
- both items, where we use a proper
$(OutputPath)
-based path rather than hard-coding it - or something with the
TfmSpecificPackageFile
-item in a target instead, becauseSentry
is multi-targeted, but Roslyn-Compiler-Extensions should benetstandard2.0
Also OutputItemType="Analyzer"
seems wrong in this context as we don't want to consume the Generator in Sentry
, but pack it in the same package alongside the Sentry lib/
.
Let me get back to that when I'm on a Windows machine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right... this would work if we only wanted to use the analyzer when building the SentrySDK:
But we want to package it and have it run when building projects that are using the Sentry SDK.
When I built a source generator myself, I simply put this in the csproj file for the analyzer itself:
https://github.com/mentaldesk/ducktype/blob/d06ab90bc698a30e33911b19901eb6833891eed9/MentalDesk.DuckType/MentalDesk.DuckType.csproj#L48-L52
Then other projects that wanted to use that source generator added a PackageReference to the analyzer.
If we published Sentry.SourcfeGenerators
as a NuGet, would it be enough to add a package reference from Sentry
to Sentry.SourceGenerators
? Would that then ensure that anyone who added Sentry also got Sentry.SourceGenerators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes ... this should work ... this is what xunit
does.
But ... I don't think we necessarily want this: Our SourceGen emits code that is depending on Sentry
. The SourceGen does not make sense without Sentry
. And also, I think it may be "dangerous" - to some degree" - to use different versions of the SourceGen-Package and the Sentry
package.
I prefer to have the SourceGen within the Sentry
package, similar to Microsoft.Extensions.Logging.Abstractions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change:
ProjectReference
to reliably build the project as a dependency in the correct order- with
ReferenceOutputAssembly
to include in$(OutputPath)
- but with
PrivateAssets="all"
so thatSentry
does not have a dependency onSentry.SourceGenerators
- with
- utilize
TargetsForTfmSpecificContentInPackage
- with a custom
Target
that packsSentry.SourceGenerators
in the expectedPackagePath
forAnalyzer
- via
PackagePath="analyzers/dotnet/cs"
- via
- with a custom
dotnet pack
(Release) and check via NuGet Package Explorer on Windows:
No package dependency to
Sentry.SourceGenerators
Does not reference the assembly
Sentry.SourceGenerators
PackagePath="analyzers/dotnet/cs"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build fails on CI though ... need to reiterate 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From failing on all Platforms now only failing on macOS ... I'm getting there 😉
@Flash0ver it looks like you finally got this working. Since it's all your work, maybe you want to delete this PR and push up a new one (put your name on it)? I don't feel like I contributed much here (except the initial complaint). btw: Can you now run the integration tests locally with this change? That was probably the main motivation for the fix. |
superseded by #4307 |
The current reference is very brittle:
This breaks integration tests when these are run locally (since not all of the above assumptions hold up when running these locally).
#skip-changelog