Skip to content
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

Omnisharp ignoring exclude options in omnisharp.json #1460

Open
sicsix opened this issue Apr 14, 2019 · 19 comments
Open

Omnisharp ignoring exclude options in omnisharp.json #1460

sicsix opened this issue Apr 14, 2019 · 19 comments

Comments

@sicsix
Copy link

sicsix commented Apr 14, 2019

Issue Description

Cannot use FileOptions to prevent Omnisharp from processing unwanted directories using the FileOptions. Also cannot prevent RoslynExtensions (Roslynator) from processing directories. Tried using omnisharp.json in project folder and omnisharp.json in user folder. It does load RoslynExtensionOptions but FileOptions does not appear to work.

Steps to Reproduce

Create a project, put .cs files in a folder, add exclude options like shown here https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options

Expected Behavior

Files are not parsed by omnisharp, and problems are not highlighted by Roslynator

Actual Behavior

Directory is processed.

Environment information

VSCode version: 1.33.1
C# Extension: 1.18.0

Dotnet Information .NET Core SDK (reflecting any global.json): Version: 2.2.203 Commit: e5bab63eca

Runtime Environment:
OS Name: Windows
OS Version: 10.0.17134
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.203\

Host (useful for support):
Version: 2.2.4
Commit: f95848e524

.NET Core SDKs installed:
1.1.0 [C:\Program Files\dotnet\sdk]
2.2.203 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Visual Studio Code Extensions
Extension Author Version
csharp ms-vscode 1.18.0
material-icon-theme PKief 3.7.0
Material-theme zhuangtongfa 2.21.0
output-colorizer IBM 0.1.2
prettier-vscode esbenp 1.8.1
theme-monokai-pro-vscode monokai 1.1.12
todo-tree Gruntfuggly 0.0.126
unity-code-snippets kleber-swf 1.3.0
unity-debug Unity 2.7.2
unity-tools Tobiah 1.1.0
vsc-material-theme Equinusocio 2.8.2
vscode-npm-script eg2 0.3.5
@filipw
Copy link
Member

filipw commented Apr 14, 2019

It seems that documentation is not being clear about that - FileOptions is used to control which projects OmniSharp should look at, not individual files.
What you are asking for is currently not supported.

I will also move this issue to https://github.com/OmniSharp/omnisharp-roslyn repo.

@filipw filipw transferred this issue from dotnet/vscode-csharp Apr 14, 2019
@aarononeal
Copy link

aarononeal commented Apr 21, 2019

@filipw This doesn't work for projects either. They still get processed.

# omnisharp.json
{
  "fileOptions": {
    "userExcludeSearchPatterns": [
      "**/test-input/msbuild/bad.csproj"
    ]
  }
}
[info]: OmniSharp.MSBuild.ProjectManager
        Adding project '/build-kit-js/test-input/msbuild/bad.csproj'
[info]: OmniSharp.MSBuild.ProjectManager
        Update project: bad

@aarononeal
Copy link

Actually, appears to be a documentation bug. The following with excludeSearchPatterns instead works:

{
  "fileOptions": {
    "excludeSearchPatterns": [
      "**/test-input/msbuild/bad.csproj"
    ]
  }
}

@zgramana
Copy link

Bumping into this with a gRPC project: omnisharp-roslyn is reporting problems found in a project's obj/… folder.

The principle of least astonishment suggests obj and bin should excluded from scanning by default.

@Malikazz
Copy link

I have the same problem with obj and bin as stated, is there no way to disable it scanning a folder? Is this something that should be in requested features?

@ijacquez
Copy link

ijacquez commented Feb 1, 2020

Is it fileOptions or FileOptions? Also, can it be used to ignore specific .dlls from coming up in a code completion?

@idrisnacer
Copy link

As a workaround for obj folder, i redirected it outside the project :

  • delete obj folder
  • create a file in the root of your project named Directory.Build.props
  • add the following to the file:
    <Project>
    <PropertyGroup>
    <MSBuildProjectExtensionsPath>..\obj\</MSBuildProjectExtensionsPath>
    <BaseIntermediateOutputPath>..\obj\</BaseIntermediateOutputPath>
    </PropertyGroup>
    </Project>

@filipw
Copy link
Member

filipw commented Feb 6, 2020

@aarononeal thanks 🤦‍♂ I corrected the docs.

@ghost
Copy link

ghost commented Feb 14, 2020

Roslyn seems to be scanning auto-gen files from the Unity Library folder, and I've tried several different versions of the globs above to exclude the respective .csproj files, but none of them seemed to work. I'll be disabling Roslyn for now, but if anyone has a workaround, specifically for this use case, I'd highly appreciate it.

@yevhen
Copy link

yevhen commented Apr 6, 2020

globbing doesn't work properly for excludeSearchPatterns (on Windows). Having **/*.csproj still scans all project files. OmniSharp: ms-dotnettools.csharp-1.21.16.omnisharp\1.34.15

@Iron-E
Copy link

Iron-E commented Apr 14, 2020

Coming here from #1766.

The description for excludeSearchPatterns and systemExcludeSearchPatterns is:

Used to define which directories and files should not be included in OmniSharp's file scanning/discovery process.

I feel like after reading everything here, that isn't truly representative of what it does. If it cannot actually exclude files from scanning, I think we should have a different description there. Ideally, the warning wouldn't be necessary. Maybe something like this would be better:

Used to define which directories and files should be included in OmniSharp's project file / solution file discovery process. Not individual .cs files.

@Iron-E
Copy link

Iron-E commented Apr 14, 2020

As for excluding specific files from the project, I have to agree with @zgramana:

The principle of least astonishment suggests obj and bin should excluded from scanning by default.

Most of the warnings in my project are from this directory. It makes real errors incredibly difficult to find. If the feature of adding excluded files and directories from actual scanning is not planned, those directories should at least be off by default, since we as developers have little control over their output.

@filipw
Copy link
Member

filipw commented Apr 14, 2020

The description for excludeSearchPatterns and systemExcludeSearchPatterns is:

Used to define which directories and files should not be included in OmniSharp's file scanning/discovery process.

I think this is semantics - Omnisharp doesn't ever "discover" .cs files since MsBuild does it. The only files OmniSharp would discover would be "sln/csproj".

Plus, there is a warning just below that explains just that (in bold!) - Warning: this features allows disabling of project file / solution file discovery not individual .cs files.. However, since this is a wiki (https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options) feel free to just edit it the way you feel like makes more sense - thanks and appreciate the help!

@2ndwolf
Copy link

2ndwolf commented Apr 20, 2020

Omnisharp isn't honoring my excludeSearchPatterns option. I have tried restarting it multiple times, trying multiple patterns ignoring libs.

Such as:

**/libs/**/*
./libs/**/*
/libs/**/*

Am I just confused?

{
  "fileOptions": {
    "systemExcludeSearchPatterns": [
      "**/node_modules/**/*",
      "**/bin/**/*",
      "**/obj/**/*",
      "**/node_modules/**/*"
    ],
    "excludeSearchPatterns": [
      "**/libs/**/*"
    ]
  },
    "formattingOptions": {
        "tabSize": 2
    }
}

image

@Smoovsky
Copy link

Smoovsky commented Jul 8, 2020

Omnisharp isn't honoring my excludeSearchPatterns option. I have tried restarting it multiple times, trying multiple patterns ignoring libs.

Such as:

**/libs/**/*
./libs/**/*
/libs/**/*

Am I just confused?

{
  "fileOptions": {
    "systemExcludeSearchPatterns": [
      "**/node_modules/**/*",
      "**/bin/**/*",
      "**/obj/**/*",
      "**/node_modules/**/*"
    ],
    "excludeSearchPatterns": [
      "**/libs/**/*"
    ]
  },
    "formattingOptions": {
        "tabSize": 2
    }
}

image

I think the reason is that once it's using the solution file, it will discover all the projects in the solution. And here is no way to ask omnisharp to disregard a .sln file if it exists in your root workspace.

@2ndwolf
Copy link

2ndwolf commented Jul 11, 2020

I've left aside that project a while ago so I'll answer the best I can.

Well they're not in my root workspace, but divided in a libs folder.
Unless you mean if they are mentioned as something that is used by the project? It would make sense then but if I remember correctly that really slowed down omnisharp. Also, Audrey.Tests.csproj was broken I think. I'm guessing the solution would be to remove references to it from the sln.

@Smoovsky
Copy link

I've left aside that project a while ago so I'll answer the best I can.

Well they're not in my root workspace, but divided in a libs folder.
Unless you mean if they are mentioned as something that is used by the project? It would make sense then but if I remember correctly that really slowed down omnisharp. Also, Audrey.Tests.csproj was broken I think. I'm guessing the solution would be to remove references to it from the sln.

I just tested it out: If there is any .sln file in your workspace(including subfolders), Omnisharp will always try to open one of them and use it as the entry point for discovery and I simply can not stop this behavior. And, Yes, it will include those projects which are referenced but not in solution.
The walkaround is also simple enough, I can create a fake solution which only contains part of the entire project tree, or, I can just temporarily rename or remove the .sln file, and reverse it later. If Omnisharp couldn't find any .sln file, it will try to discover the workspace folder while honoring the exclude section in omnisharp.json

@Davilink
Copy link

Solution Filter maybe can help
#1952

@RamunasAdamonis
Copy link

Did someone managed to make it work with solution filter and has a working example to share?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests