dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

xproj ignored. CodeLens don't show References, Find All References don't work #962

Closed valery-shinkevich closed 7 years ago

valery-shinkevich commented 7 years ago

Environment data

dotnet --info output: .NET Command Line Tools (1.0.0-preview3-003805)

Product Information: Version: 1.0.0-preview3-003805 Commit SHA-1 hash: edf2fc1f53

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64

VS Code version: 1.7.1 C# Extension version: 1.5.2

Steps to reproduce

Create solution with VS 2015 (with last Core updates). Works fine. Open solution folder in VSCode - CodeLens don't show References, Find All References don't work.

https://cloud.githubusercontent.com/assets/1697801/20385121/31689772-acc7-11e6-965a-3f00b0e07869.jpg

OmniSharp log

Starting OmniSharp server at 18.11.2016, 12:03:36 Target: c:\NewProject\New\LombardService

OmniSharp server started Path: C:\Users\WaSh.vscode\extensions\ms-vscode.csharp-1.5.2\bin\omnisharp\OmniSharp.exe PID: 7108

OmniSharp: -s c:\NewProject\New\LombardService --hostPID 11100 --stdio DotNet:enablePackageRestore=false --encoding utf-8 [INFORMATION:OmniSharp.Startup] Omnisharp server running using Stdio at location 'c:\NewProject\New\LombardService' on host 11100. [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Initializing in c:\NewProject\New\LombardService [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Auto package restore: False [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Update workspace context [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Resolving projects references [INFORMATION:OmniSharp#MSBuild] Detecting projects in 'c:\NewProject\New\LombardService\LombardServiceNew.sln'. [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'src\LombardService.Data\LombardService.Data.xproj' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'src\LombardService.Services\LombardService.Services.xproj' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'tests\LombardService.Services.Tests\LombardService.Services.Tests.xproj' [INFORMATION:OmniSharp.Startup] Configuration finished.

DustinCampbell commented 7 years ago

It's 100% expected that xproj is ignored. xproj doesn't actually have any significant information about your projects. That information is all in the project.json. So, the real concern is that it doesn't find any project.json files in your log.

I have a couple of questions:

DustinCampbell commented 7 years ago

I created a .NET Core Web Application in Visual Studio 2015 using the latest .NET Core tools for Visual Studio and the .NET Core CLI available at https://dot.net and it worked fine:

Starting OmniSharp server at 11/21/2016, 10:23:13 AM
    Target: c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1

OmniSharp server started
    Path: C:\Users\dusti\.vscode\extensions\ms-vscode.csharp-1.5.3\bin\omnisharp\OmniSharp.exe
    PID: 22480

OmniSharp: -s c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1 --hostPID 6920 --stdio DotNet:enablePackageRestore=false --encoding utf-8
[INFORMATION:OmniSharp.Startup] Omnisharp server running using Stdio at location 'c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1' on host 6920.
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Initializing in c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Auto package restore: False
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Update workspace context
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Update project c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1\src\WebApplication1
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Add project c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1\src\WebApplication1\project.json => 46ca2ab4-204e-410c-b755-6439b91a4da8
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Resolving projects references
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem]   Processing [ProjectState] WebApplication1/.NETCoreApp,Version=v1.0
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem]     Added 183 and removed 0 file references
[INFORMATION:OmniSharp.DotNet.DotNetProjectSystem]     Added 3 and removed 0 documents.
[INFORMATION:OmniSharp#MSBuild] Detecting projects in 'c:\Users\dusti\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1.sln'.
[WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'src'
[WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'Solution Items'
[WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'src\WebApplication1\WebApplication1.xproj'
[INFORMATION:OmniSharp.Startup] Configuration finished.
DustinCampbell commented 7 years ago

Here's a screenshot of it working properly:

image

DustinCampbell commented 7 years ago

From your screenshots, it looks like you are using a different project rather than what you described in the repro steps. Could you provide a project that reproduces this issue?

valery-shinkevich commented 7 years ago

I created a new project, because I removed the previous project files. It is slightly different in structure, but the meaning is the same.

screenshot

core2

solution

LombardServiceNew.zip

Log

Starting OmniSharp server at 21.11.2016, 23:07:22 Target: c:\NewProject\New\LombardServiceNew

OmniSharp server started Path: C:\Users\WaSh.vscode\extensions\ms-vscode.csharp-1.5.2\bin\omnisharp\OmniSharp.exe PID: 8648

OmniSharp: -s c:\NewProject\New\LombardServiceNew --hostPID 3748 --stdio DotNet:enablePackageRestore=false --encoding utf-8 [INFORMATION:OmniSharp.Startup] Omnisharp server running using Stdio at location 'c:\NewProject\New\LombardServiceNew' on host 3748. [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Initializing in c:\NewProject\New\LombardServiceNew [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Auto package restore: False [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Update workspace context [INFORMATION:OmniSharp.DotNet.DotNetProjectSystem] Resolving projects references [INFORMATION:OmniSharp#MSBuild] Detecting projects in 'c:\NewProject\New\LombardServiceNew\LombardServiceNew.sln'. [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'src' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'tests' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'LombardService.Data\LombardService.Data.xproj' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'LombardService.Services\LombardService.Services.xproj' [WARNING:OmniSharp#MSBuild] Skipped unsupported project type 'LombardService.Sevices.Tests\LombardService.Sevices.Tests.xproj' [INFORMATION:OmniSharp.Startup] Configuration finished.

dotnet info

.NET Command Line Tools (1.0.0-preview2-1-003177)

Product Information: Version: 1.0.0-preview2-1-003177 Commit SHA-1 hash: a2df9c2576

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x86

valery-shinkevich commented 7 years ago

also it don't work with dotnet --info

.NET Command Line Tools (1.0.0-preview3-003805)

Product Information: Version: 1.0.0-preview3-003805 Commit SHA-1 hash: edf2fc1f53

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64

DustinCampbell commented 7 years ago

It looks like you restructured your project and deleted the global.json. That defines search paths used to locate your projects when project.json is used. Without that, VS Code won't be able to process your projects. https://docs.microsoft.com/dotnet/articles/core/tools/global-json.

Note that ASP.NET Core applications really like to be in a particular directory structure.

WRT dotnet --info, I've seen situations where installing a newer CLI can mess with the VS tooling.

valery-shinkevich commented 7 years ago

Just forgot to create a global.json. But I've added it to the folder with the solution. Nothing has changed - codeLens is not working. { "projects": [ "LombardService.Data", "LombardService.Services", "LombardService.Services.Tests" ] }

valery-shinkevich commented 7 years ago

Added

"sdk": {
"version": "1.0.0-preview2-1-003177"
} 

but it did not help

valery-shinkevich commented 7 years ago

What is the way for me to get more information from OmniSharp, and try to dig deeper ?

DustinCampbell commented 7 years ago

@valery-shinkevich: I haven't dug too deeply yet, but it appears to me that the issue has to do with folder depth. If I use your structure, it fails to find the project.json files. However, if I use the "src" and "test" folders that are created for me by the project template in VS 2015, it works fine.

DustinCampbell commented 7 years ago

From reading the code in OmniSharp, I think I see where the bug is. I'm looking at this code: https://github.com/OmniSharp/omnisharp-roslyn/blob/dev/src/OmniSharp.DotNet/Projects/ProjectSearcher.cs#L76-L83

return globalSettings.ProjectSearchPaths
    .Select(searchPath => Path.Combine(globalSettings.DirectoryPath, searchPath))
    .Where(actualPath => Directory.Exists(actualPath))
    .SelectMany(actualPath => Directory.GetDirectories(actualPath))
    .Where(actualPath => File.Exists(Path.Combine(actualPath, Project.FileName)))
    .Select(path => Path.GetFullPath(path))
    .Distinct(StringComparer.OrdinalIgnoreCase)
    .ToList();

It looks to me like the SelectMany(...) after the initial Where(...) clause causes it skip searches the directories defined in the global.json and only look in directories underneath them.

DustinCampbell commented 7 years ago

Note that there's a bit of information that might be helpful here on StackOverflow: http://stackoverflow.com/questions/34791682/explanation-of-the-projects-section-in-global-json-in-asp-net-5

DustinCampbell commented 7 years ago

Yeah, I just debugged through OmniSharp and that's definitely where the failure is.

DustinCampbell commented 7 years ago

For now, if you put your projects in the expected directory structure it will work. We should be able to address this in the next release of the C# extension.

DustinCampbell commented 7 years ago

It turns out that this issue and #904 have the same root cause. Linking them...

DustinCampbell commented 7 years ago

This is fixed in OmniSharp now. Once we take a new build for the extension, we'll publish a beta that you can try. Otherwise, the fix will be available when we ship 1.6 of the extension in the coming weeks.

DustinCampbell commented 7 years ago

I've created a v1.6-beta2 release of the C# extension that contains this fix, among others. See this page for information on installing beta releases

valery-shinkevich commented 7 years ago

Thank you. I just now saw your post. Everything is working! References displays as it should!

DustinCampbell commented 7 years ago

Glad to hear it!