omnisharp-roslyn icon indicating copy to clipboard operation
omnisharp-roslyn copied to clipboard

Project reload loop due to change in MSBuild generated EditorConfig file

Open ralish opened this issue 2 years ago • 1 comments

In some scenarios OmniSharp can get stuck in a "loop" where it continually re-analyzes a project due to a change in the MSBuild generated EditorConfig file for the project. To reproduce this issue a configuration like the below can be used:

  • Open a workspace in Visual Studio Code containing a C# project
  • Ensure OmniSharp EditorConfig support is enabled (default)
    The associated VS Code setting is: omnisharp.enableEditorConfigSupport
  • If on-demand loading of projects is enabled (non-default) open a C# source file in the project
    The associated VS Code setting is: omnisharp.enableLoadMsBuildProjectsOnDemand
  • Open the same C# project in Visual Studio (or the associated solution)
  • To trigger the issue build the project in Visual Studio (tested with VS2019) A rebuild may be required if the build outputs are up-to-date

At this point Visual Studio and OmniSharp will start conflicting with each other. As best I can tell, in building the project Visual Studio via MSBuild generates a slightly different EditorConfig file from the one which OmniSharp generates (see below). This causes OmniSharp to reload the project configuration as it watches for changes to the generated EditorConfig file. The project reload causes the same EditorConfig file to be regenerated, with a slight difference, and in turn Visual Studio notices the change, performs its own reload, and the cycle repeats.

By capturing the generated <projectname>.GeneratedMSBuildEditorConfig.editorconfig from each product I was able to compare the outputs and the only difference is the case of the drive letter for the build_property.ProjectDir property.

Visual Studio 2019

build_property.ProjectDir = C:\Users\SDL\Code\Personal\DecodeWheaRecord\src\

OmniSharp

build_property.ProjectDir = c:\Users\SDL\Code\Personal\DecodeWheaRecord\src\

I'm not sure what the best fix here is. Assuming that OmniSharp should be watching for changes in the MSBuild generated EditorConfig file, it may be that the simplest fix is to ensure that any drive letter in a project path is upper-cased to match Visual Studio. That way, the generated MSBuild EditorConfig files will match and both IDEs can have the same project open side-by-side, hopefully co-existing in peace and harmony.

As a workaround you can disable EditorConfig support in OmniSharp by disabling the above referenced configuration option.

ralish avatar Sep 07 '21 04:09 ralish

Adding VS Code Settings screenshot referring the above solution for reference

image

kritulrathod avatar Sep 14 '21 01:09 kritulrathod