I recently wrote an analyzer that used IOperation
. It was easy enough to make it work correctly, but I don't understand any of the ramifications. I'd love some guidance from the Roslyn team about the end-to-end story.
// (Step 1) Write the analyzer with a dependency on NuGet package Microsoft.CodeAnalysis v2.1.0
public override void Initialize(AnalysisContext context) {
context.RegisterOperationAction(AnalyzeAwaitOperation, OperationKind.AwaitExpression);
}
// (Step 2) Edit the csproj of a project that *uses* my analyzer:
<Project ...>
<PropertyGroup>
<Features>IOperation</Features>
...
My overall question is: I am writing an analyzer with target audience XYZ. Can I reasonable use IOperation to write my analyzer?
I know how to answer that question if XYZ is solely myself :) but don't know what the answer is for all other possible audiences. Here are some of the dead-ends I researched trying to figure out the answer...
Q1. I understand that this msbuild Features flag translates into the csc.exe flag /features:IOperation
, but I only got this by digging through the Roslyn reference source. This command-line argument doesn't seem to be listed on any of the public docs about CSC command line arguments. Should it be?
Q2. What happens if someone does /features:IOperation
in a version of C# that doesn't support it? What happens when you do it in C#5? C#6?
Q3. If I write an analyzer that uses IOperation, presumably there's a minimum Microsoft.CodeAnalysis NuGet version that I must reference. Is that minimum 2.1.0?
Q4. What happens if I invoke csc.exe /a:MyAnalyzer.dll
when MyAnalyzer depends on a version of Microsoft.CodeAnalysis NuGet package that's newer than what csc.exe supports?
Q5. Based on Q3 and Q4, are there any versions of csc.exe where its DLL version-checks allow me to /a:MyIOperationAnalyzer.dll
but where it doesn't support /feature:IOperation
?
Q6. Is IOperation still considered an experimental feature that shouldn't be used for proper productionized analyzers?
:)
My understanding is that IOperstion is an experimental feature that will undergo breaking changes between now and when it reaches RTM.
Any updates? What will happen if I use this feature in v1.3.2?
@mavasani Can you reply with the first version of Roslyn where IOperation is stable and see if this can be closed? I can't figure it out due to #29649 and #29650.
2.6.1 is the recommended minimum version with first fully supported IOperation release.
Most helpful comment
:)