0

I wrote a custom DiagnosticAnalyzer and want to use it in Visual Studio Code with Omnisharp. The analyzer is based on the Visual Studio solution template "Analyzer with Code Fix (.NET Standard)" containing five projects (with suffixes .CodeFixes, .Package, .Test and .Vsix and one without suffix). I copied this solution to the solution where I want the analyzer to be run. Based on this article on how to reference analyzers from a project, I also added a file there called Directory.Build.props with the following contents:

<Project>
  <ItemGroup>
    <ProjectReference Include="$(MSBuildThisFileDirectory)_UnityAnalyzer\UnitySerializedFieldNamingRule\UnitySerializedFieldNamingRule\UnitySerializedFieldNamingRule.csproj"
                      PrivateAssets="all"
                      ReferenceOutputAssembly="false"
                      OutputItemType="Analyzer" />
    <ProjectReference Include="$(MSBuildThisFileDirectory)UnityAnalyzer\UnitySerializedFieldNamingRule\UnitySerializedFieldNamingRule.CodeFixes\UnitySerializedFieldNamingRule.CodeFixes.csproj"
                      PrivateAssets="all"
                      ReferenceOutputAssembly="false"
                      OutputItemType="Analyzer" />
  </ItemGroup>
</Project>

This file is read and the paths should be correct, because initially OmniSharp complained about not finding the .csproj files until I corrected the paths to what they are now. Now I don't get any errors, but also no warnings from my analyzer.
For testing I also added dotnet_diagnostic.UnitySerializedFieldNamingRule.severity = error to my .editorconfig (from which other settings do get picked up).
In test cases in the .Test project the analyzer works as expected.

How can I get OmniSharp to run my custom analyzer or narrow down what's currently going wrong?

itkdk
  • 11
  • 2

1 Answers1

0

I fixed the problem by building the analyzer solution in Visual Studio and then copying the two projects without postfix and with .CodeFix to the other solution again.

itkdk
  • 11
  • 2