Closed CollinAlpert closed 1 month ago
I managed to pack the analyzer with the Carter package and still keep the analyzer project netstandard2.0
. This will ensure maximum compatibility across Visual Studio versions.
Also since the analyzer is now also added to the Carter project, we got a hit. The CarterModule
class has a constructor with a parameter and thus the analyzer flags this. I've disabled the warning for now, however let me know if you want me to tweak the analyzer in this regard.
Looking good - excuse my ignorance but any reason why we can't delete the analyzer project and just put the analyzer classes inside Carter?
No worries! We can do that, however the analyzer might not work for a very small amount of users due to the targeting of net8.0
instead of netstandard2.0
as recommended. But like I said, I see only minimal risk so I am fine with it. I will make the changes.
If I put in a ctor dependency in the Carter.Sample project that has a project ref to Carter will I still get a warning?
Yes, you will, however the project reference must look like this to include analyzer behavior:
<ProjectReference Include="../../src/Carter/Carter.csproj" OutputItemType="Analyzer" />
OutputItemType
is not necessary for PackageReference
elements, since we pack the DLL in the analyzer directory, something that is not possible to ProjectReference
elements.
Should rename it to Carter
from CARTER1
?
We could, however I wouldn't recommend it. The guidelines for diagnostic IDs recommend using the project name + a number. If you decide you want another analyzer to warn about something else in the future, you'd need to distinguish it from this one, e.g. by naming it CARTER2
. The compiler diagnostics (CSXXXX
), code analysis diagnostics (CAXXXX
) and system library diagnostics (SYSLIBXXXX
) all follow this pattern.
Can you rebase, I've added some permissions to the actions workflow file :)
Actually GH has a button to do it :)
Thanks for this!! Appreciate it 👍 👍
Happy to be of assistance! Ping me if you want any other rules implemented 😄
As promised, I have created a Roslyn Analyzer which emits a warning when a type implementing
ICarterModule
has a constructor with parameters. Feel free to look over the test cases and see if you agree with the behavior.