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 doesn't work for WebApplication projects #1368

Closed
m0sa opened this issue Apr 7, 2017 · 10 comments
Closed

OmniSharp doesn't work for WebApplication projects #1368

m0sa opened this issue Apr 7, 2017 · 10 comments
Assignees
Milestone

Comments

@m0sa
Copy link

m0sa commented Apr 7, 2017

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.2)

Product Information:
 Version:            1.0.2
 Commit SHA-1 hash:  54743c8b7b

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

VS Code version: 1.12.0 insiders
C# Extension version: 1.8.1

image

Steps to reproduce

Open a folder with an WebApplication csproj in vscode

Expected behavior

Omnisharp should work

Actual behavior

Omnisharp doesn't load the csproj, the relevant errors in the output:

[info]: OmniSharp.MSBuild.MSBuildProjectSystem
        Loading project from 'SomeProject.csproj'.
[warn]: OmniSharp.MSBuild.MSBuildProjectSystem
        Failed to process project file 'SomeProject.csproj'.
SomeProject.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The imported project "~\.vscode-insiders\extensions\ms-vscode.csharp-1.8.1\bin\omnisharp\msbuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "~\.vscode-insiders\extensions\ms-vscode.csharp-1.8.1\bin\omnisharp\OmniSharp.exe.Config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.  SomeProject.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Evaluation.Evaluator`4.ThrowForImportedProjectWithSearchPathsNotFound(ProjectImportPathMatch searchPathMatch, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
   at Microsoft.Build.Evaluation.Project.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
   at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Create(String projectFilePath, String solutionDirectory, ILogger logger, MSBuildOptions options, ICollection`1 diagnostics, Boolean isUnityProject)
   at OmniSharp.MSBuild.MSBuildProjectSystem.CreateProjectFileInfo(String projectFilePath, Boolean isUnityProject)

The relevant line from the .csproj file:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
@DustinCampbell
Copy link
Member

OmniSharp doesn't include all of the necessary tasks and targets needed to process any project. The error that MSBuild returned is telling:

The imported project "~\.vscode-insiders\extensions\ms-vscode.csharp-1.8.1\bin\omnisharp\msbuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "~\.vscode-insiders\extensions\ms-vscode.csharp-1.8.1\bin\omnisharp\OmniSharp.exe.Config". Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths. SomeProject.csproj

Do you have Microsoft.WebApplication.targets anywhere on your system?

@m0sa
Copy link
Author

m0sa commented Apr 7, 2017 via email

@DustinCampbell
Copy link
Member

When was it working? Did it work recently in C# for VS Code but some update (maybe to VS 2017) broke it?

@DustinCampbell
Copy link
Member

I tried creating a new ASP .NET Web Application (MVC) in VS 2017 and didn't encounter this error. Do you have project that you'd be willing to share out to help repro this problem?

@DustinCampbell
Copy link
Member

Eureka! I can repro if I launch VS Code from a VS 2017 Developer Command Prompt, but not from a normal Windows Command Prompt. Do you see the same behavior?

@DustinCampbell
Copy link
Member

OK. Digging in a bit, it seems that the presence of the VisualStudioVersion=15.0 environment variable causes it to fail. I suspect this is causing MSBuild to take some other code path. Digging further...

@DustinCampbell DustinCampbell added this to the 1.9 milestone Apr 7, 2017
DustinCampbell added a commit to DustinCampbell/omnisharp-roslyn that referenced this issue Apr 7, 2017
…l Studio 2017 if it's present

Fixes dotnet/vscode-csharp#1368

This change ensures that OmniSharp will use the MSBuild tools installed with Visual Studio 2017 if they're present on the machine. This allows OmniSharp to properly handle VS 2017 projects where the targets/tasks aren't include with OmniSharp's local MSBuild, such as WebApplication projects as reported in the bug listed above. If VS 2017 is not on the machine, OmniSharp will continue to use its local MSBuild which has a fallback to the Microsoft Build Tools for targets/tasks that it can't find.

I've also taken the opportunity to clean up a lot of the MSBuild environment initialized code and project file processing.
@m0sa
Copy link
Author

m0sa commented Apr 7, 2017

Yup, I can confirm it only happens in a 2017 Developer Command Prompt. Thanks for digging into it.

@DustinCampbell
Copy link
Member

This will be fixed when we take a new build of OmniSharp into the VS Code extension.

@darkguy2008
Copy link

We're almost in June, when will that be?

@DustinCampbell
Copy link
Member

This already happened and the issue was closed. It was fixed in C# for VS Code 1.9. if you're experiencing a similar problem, could you file a new issue?

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

3 participants