dotnet / vscode-csharp

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

Project fails to load, SDK 'Microsoft.NET.Sdk.Razor' not found #2604

Open fogzot opened 6 years ago

fogzot commented 6 years ago

I know there are other issues with the same behavior but they mostly refer to MacOS and the fix seems to be to install an up to date Mono. The issue I am experiencing happens on Linux, with the latest version of Mono installed.

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.403
 Commit:    04e15494b6

Runtime Environment:
 OS Name:     debian
 OS Version:  
 OS Platform: Linux
 RID:         debian-x64
 Base Path:   /usr/share/dotnet/sdk/2.1.403/

Host (useful for support):
  Version: 2.1.5
  Commit:  290303f510

.NET Core SDKs installed:
  2.1.403 [/usr/share/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

VS Code version:

Version: 1.28.1
Commit: 3368db6750222d319c851f6d90eb619d886e08f5
Date: 2018-10-11T18:09:20.566Z
Electron: 2.0.9
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

C# Extension version:

1.16.2

Mono version:

Mono JIT compiler version 5.16.0.179 (tarball Thu Oct  4 10:24:32 UTC 2018)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
    TLS:           __thread
    SIGSEGV:       altstack
    Notifications: epoll
    Architecture:  amd64
    Disabled:      none
    Misc:          softdebug 
    Interpreter:   yes
    LLVM:          yes(3.6.0svn-mono-/)
    GC:            sgen (concurrent by default)

Steps to reproduce

Just load any project with latest version on Linux. The exception is always the same:

Starting OmniSharp server at 10/12/2018, 10:02:57 AM
    Target: /home/fog/Customers/ventana/yes3/Yes.sln

OmniSharp server started with Mono 5.16.0.
    Path: /home/fog/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.5/omnisharp/OmniSharp.exe
    PID: 9601

[info]: OmniSharp.Stdio.Host
        Starting OmniSharp on debian 0.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
        DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Located 2 MSBuild instance(s)
            1: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            2: StandAlone 15.0 - "/home/fog/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.5/omnisharp/msbuild/15.0/Bin"
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
        Registered MSBuild instance: Mono 15.0 - "/usr/lib/mono/msbuild/15.0/bin"
            CscToolPath = /home/fog/.vscode/extensions/ms-vscode.csharp-1.16.2/.omnisharp/1.32.5/omnisharp/msbuild/15.0/Bin/Roslyn
            CscToolExe = csc.exe
[info]: OmniSharp.Cake.CakeProjectSystem
        Detecting Cake files in '/home/fog/Customers/ventana/yes3'.
[info]: OmniSharp.Cake.CakeProjectSystem
        Could not find any Cake files
[info]: OmniSharp.WorkspaceInitializer
        Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
[info]: OmniSharp.MSBuild.ProjectSystem
        Detecting projects in '/home/fog/Customers/ventana/yes3/Yes.sln'.
[info]: OmniSharp.MSBuild.ProjectManager
        Queue project update for '/home/fog/Customers/ventana/yes3/backoffice/Backoffice.csproj'
[info]: OmniSharp.Script.ScriptProjectSystem
        Detecting CSX files in '/home/fog/Customers/ventana/yes3'.
[info]: OmniSharp.MSBuild.ProjectManager
        Loading project: /home/fog/Customers/ventana/yes3/backoffice/Backoffice.csproj
[info]: OmniSharp.Script.ScriptProjectSystem
        Could not find any CSX files
[info]: OmniSharp.WorkspaceInitializer
        Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
[info]: OmniSharp.WorkspaceInitializer
        Configuration finished.
[info]: OmniSharp.Stdio.Host
        Omnisharp server running using Stdio at location '/home/fog/Customers/ventana/yes3' on host 9448.
[warn]: OmniSharp.MSBuild.ProjectManager
        Failed to load project file '/home/fog/Customers/ventana/yes3/backoffice/Backoffice.csproj'.
/home/fog/Customers/ventana/yes3/backoffice/Backoffice.csproj(1,1)
Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Razor' specified could not be found.  /usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk.Web/Sdk/Sdk.props
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject (System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, System.Object[] args) [0x00040] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1] (System.Boolean condition, System.String errorSubCategoryResourceName, Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00003] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1] (Microsoft.Build.Shared.IElementLocation elementLocation, System.String resourceName, T1 arg0) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ExpandAndLoadImportsFromUnescapedImportExpressionConditioned (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, System.Collections.Generic.List`1[Microsoft.Build.Construction.ProjectRootElement]& projects, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult, System.Boolean throwOnFileNotExistsError) [0x0024e] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].ExpandAndLoadImports (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement, Microsoft.Build.BackEnd.SdkResolution.SdkResult& sdkResult) [0x00027] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x0000d] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x00209] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].EvaluateImportElement (System.String directoryOfImportingFile, Microsoft.Build.Construction.ProjectImportElement importElement) [0x00040] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].PerformDepthFirstPass (Microsoft.Build.Construction.ProjectRootElement currentProjectOrImport) [0x000e6] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Framework.BuildEventContext buildEventContext) [0x00103] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Evaluator`4[P,I,M,D].Evaluate (Microsoft.Build.Evaluation.IEvaluatorData`4[P,I,M,D] data, Microsoft.Build.Construction.ProjectRootElement root, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, System.Int32 maxNodeCount, Microsoft.Build.Collections.PropertyDictionary`1[T] environmentProperties, Microsoft.Build.BackEnd.Logging.ILoggingService loggingService, Microsoft.Build.Evaluation.IItemFactory`2[S,T] itemFactory, Microsoft.Build.Evaluation.IToolsetProvider toolsetProvider, Microsoft.Build.Evaluation.ProjectRootElementCache projectRootElementCache, Microsoft.Build.Framework.BuildEventContext buildEventContext, Microsoft.Build.Execution.ProjectInstance projectInstanceIfAnyForDebuggerOnly, Microsoft.Build.BackEnd.SdkResolution.ISdkResolverService sdkResolverService, System.Int32 submissionId, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x0001a] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project.Reevaluate (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x0004c] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00034] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.BackEnd.Logging.ILoggingService loggingServiceForEvaluation) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary (Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00023] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project.Initialize (System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x00126] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings, Microsoft.Build.Evaluation.Context.EvaluationContext evaluationContext) [0x0009e] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, System.String subToolsetVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection, Microsoft.Build.Evaluation.ProjectLoadSettings loadSettings) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.Project..ctor (System.String projectFile, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion, Microsoft.Build.Evaluation.ProjectCollection projectCollection) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.Collections.Generic.IDictionary`2[TKey,TValue] globalProperties, System.String toolsVersion) [0x000f7] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at Microsoft.Build.Evaluation.ProjectCollection.LoadProject (System.String fileName, System.String toolsVersion) [0x00000] in <63bca7756d124ea392a81ca1b2d26b9c>:0 
  at OmniSharp.MSBuild.ProjectLoader.EvaluateProjectFileCore (System.String filePath) [0x0003e] in <99f3a3b619ce4010a7d6d489ffd5bcf1>:0 
  at OmniSharp.MSBuild.ProjectLoader.BuildProject (System.String filePath) [0x0000d] in <99f3a3b619ce4010a7d6d489ffd5bcf1>:0 
  at OmniSharp.MSBuild.ProjectFile.ProjectFileInfo.Load (System.String filePath, OmniSharp.MSBuild.ProjectLoader loader) [0x00015] in <99f3a3b619ce4010a7d6d489ffd5bcf1>:0 
  at OmniSharp.MSBuild.ProjectManager+<>c__DisplayClass25_0.<LoadProject>b__0 () [0x00000] in <99f3a3b619ce4010a7d6d489ffd5bcf1>:0 
  at (wrapper delegate-invoke) System.Func`1[System.ValueTuple`3[OmniSharp.MSBuild.ProjectFile.ProjectFileInfo,System.Collections.Immutable.ImmutableArray`1[OmniSharp.MSBuild.Logging.MSBuildDiagnostic],OmniSharp.MSBuild.Notification.ProjectLoadedEventArgs]].invoke_TResult()
  at OmniSharp.MSBuild.ProjectManager.LoadOrReloadProject (System.String projectFilePath, System.Func`1[TResult] loader) [0x0001b] in <99f3a3b619ce4010a7d6d489ffd5bcf1>:0 

[fail]: OmniSharp.MSBuild.ProjectManager
        Attemped to update project that is not loaded: /home/fog/Customers/ventana/yes3/backoffice/Backoffice.csproj
rchande commented 6 years ago

@fogzot Do non-Razor projects work (eg dotnet new console)?

arlomba commented 6 years ago

I had a similar issue, but solved it. Try adding this to your PATH variable (.bashrc, .zshrc...):

MSBuildSDKsPath=/path/to/dotnet/sdk
# export MSBuildSDKsPath=/opt/dotnet/sdk/2.1.403/Sdks
# export PATH=$MSBuildSDKsPath:$PATH

I'm on Arch, so you'll probably need to modify the path.

DanteMarshal commented 5 years ago

@anticide 's method worked for me. MSBuildSDKsPath="/usr/share/dotnet/sdk/2.1.403/Sdks/" on Ubuntu Though before I changed it, I noticed the path to Mono Sdks (instead of DotNet Sdks) was being used by Omnisharp.

As you can see in the exception's message, The following path was used : "/usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk.Web/Sdk/Sdk.props"

I don't know how omnisharp works in depth, But I think the problem is that Omnisharp (or maybe even msbuild, not sure) either doesn't know whether to use Mono or dotnet for a project, Or maybe it's just some Path variable conflict.

Note : I haven't tried it, But I think another workaround is to remove your Mono Sdks :grin: Though that's not a wise choice if you're gonna need it.

humamAbedrabbo commented 5 years ago

i had this problem on ubuntu 18.04, when i installed mono-complete and mono-develop after installing dotnet core. When i removed mono, and reinstall apt-transport-https from dotnet, the problem disappeared

fogzot commented 5 years ago

@fogzot Do non-Razor projects work (eg dotnet new console)?

Yes. If the project doesn't contain a reference to the Web SDK (not explicitly the Razor one, just Web) everything works.

fogzot commented 5 years ago

I can confirm that setting MSBuildSDKsPath to the .NET Core sdks directory fixes the issue.

arlomba commented 5 years ago

A better solution would be:

export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks

This way you don't have to update SDK's version.

anorborg commented 5 years ago

Has there ever been an explanation of this? I see this error pop up fairly regularly around msbuild sdk resolution. Here is a similar issue logged over there: https://github.com/Microsoft/msbuild/issues/2532. Should setting MSBuildSDKsPath be required? Is there a corruption of some installation of the tooling?

DanteMarshal commented 5 years ago

The problem is, that msbuild is also used by mono IDEs like MonoDevelop, So the previous path which is set to Mono SDKs (instead of dotnet SDKs) may be required by an IDE that compiles Mono code. I haven't tried, But setting MSBuildSDKsPath may indeed conflict with mono IDEs.

I'll check to see if it happens and update this comment asap. If it does, Perhaps a better way is to add the following in VS Code's launch script :

For Ubuntu users : export MSBuildSDKsPath=/usr/share/dotnet/sdk/$(dotnet --version)/Sdks/

For Arch users : export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks

UPDATE : I tested a simple console project using MonoDevelop 7 (FlatPack version though), and there was no problem. Since the issue is closed and continued on other places I'll be watching them now.

nguerrera commented 5 years ago

There are a few things at play here. Let me give some background on how this is supposed to work. When MSBuild encounters <Project Sdk=...>, <Import Sdk=...> or <Sdk ...>, it calls into its SdkResolvers. These are plugins that live alongside MSBuild. One in particular, Microsoft.DotNet.MSBuildSdkResolver, resolves Sdks from the .NET Core SDK location based on dotnet being on PATH. There is also a default resolver that looks in MSBuildSdksPath. The default resolver is used if the plugin resolvers are not present or fail to find the Sdk in question. (* Technically, there is a priority given to each resolver and default resolver can go in between plugins, but the priorities aren't assigned that way in practice.)

This error indicates that the default resolver was used to locate the Web SDK (because its Sdk.props is not in a .NET Core SDK location, but rather in the default MSBuildSdksPath), but then it failed to find the Razor SDK in the same default location:

Microsoft.Build.Exceptions.InvalidProjectFileException: The SDK 'Microsoft.NET.Sdk.Razor' specified could not be found.  /usr/lib/mono/msbuild/15.0/bin/Sdks/Microsoft.NET.Sdk.Web/Sdk/Sdk.props

So the first issue I see is that this mono msbuild is bundling Microsoft.NET.Sdk.Web without its Microsoft.NET.Sdk.Razor dependency. This means that the default sdk resolver will never be able to load web projects. Mono msbuild should bundle Microsoft.NET.Sdk.Razor if it is going to bundle Microsoft.NET.Sdk.Web in its default MSBuildSdksPath.

This default resolver would only be used if Microsoft.DotNet.MSBuildSdkResolver failed, which would happen in some normal circumstances:

From other hints above, these do not seem to apply here, but those are still the first things to check.

The next thing to verify is that the mono msbuild being used has Microsoft.DotNet.MSBuildSdkResolver in . /usr/lib/mono/msbuild/15.0/bin/SdkResolvers.

Finally, if it does, then there may be a bug in Microsoft.DotNet.MSBuildSdkResolver, which would fall on me. You can get the resolver to trace info to stderr by setting COREHOST_TRACE=1 as demonstrated at https://github.com/OmniSharp/omnisharp-vscode/issues/1849#issuecomment-343180388

cc @akoeplinger @radical

nguerrera commented 5 years ago

So the first issue I see is that this mono msbuild is bundling Microsoft.NET.Sdk.Web without its Microsoft.NET.Sdk.Razor dependency.

See also Microsoft/msbuild#3829

rchande commented 5 years ago

@nguerrera Thanks for the detailed explanation! @anorborg @fogzot Can you try looking through the items Nick suggested to help us figure out what the problem is?

marek-safar commented 5 years ago

@nguerrera great analysis! We are now tracking this issue on Mono side as well

fogzot commented 5 years ago

@nguerrera thank you for the explanation. @rchande I think the problem is that OmniSharp uses msbuild from the Mono distribution and Mono doesn't include Microsoft.NET.Sdk.Razor. I don't know why but when Mono msbuild is used, this part of the process doesn't hold true:

One in particular, Microsoft.DotNet.MSBuildSdkResolver, resolves Sdks from the .NET Core SDK location based on dotnet being on PATH.

Because my .NET Core SDK dotnet executable is in path but gets completely ignored.

rchande commented 5 years ago

@marek-safar Do you have an issue number we can track?

rchande commented 5 years ago

@marek-safar Never mind, I see you linked it above :)

deepak-khopade-isdr commented 5 years ago

@marek-safar, is there any way I can use older version of mono than 5.16.0 Stable which I can use on Ubuntu 16.04. I am still on .NET Core 1.1.0 with few projects added as a references which are full .NET 4.6.2 versions. This all use to build properly with my Rider on Ubuntu; but after installing new mono, its breaking now. Any help until above issues resolved with latest mono would be a great help. Thanks.

marek-safar commented 5 years ago

You'd need to check your package manager manual. If I remember correctly on Ubuntu you should be able to do something like sudo apt-get install mono-complete=<version> to downgrade automatically.

akoeplinger commented 5 years ago

For .deb-based distributions you'd need to use the snapshot repositories we provide: https://www.mono-project.com/docs/getting-started/install/linux/#accessing-older-releases

E.g. for Ubuntu 16.04 it'd be:

# remove existing stable mono
sudo apt remove mono-complete
sudo rm /etc/apt/sources.list.d/mono-official-stable.list

# add 5.14 snapshot repo
echo "deb https://download.mono-project.com/repo/ubuntu stable-xenial/snapshots/5.14.0 main" | sudo tee /etc/apt/sources.list.d/mono-official-snapshot.list
sudo apt update
sudo apt install mono-complete
deepak-khopade-isdr commented 5 years ago

Thanks, @marek-safar, @akoeplinger

TheBuzzSaw commented 5 years ago

Note : I haven't tried it, But I think another workaround is to remove your Mono Sdks grin Though that's not a wise choice if you're gonna need it.

I was having tons of issues. (Running Arch.) I gave this a go, and my problems vanished. @Marshal313 you are my hero. Seriously, why is having Mono installed from the repos such a source of problems? :(

jsoques commented 5 years ago

This started to happen to me on Windows 10!! I was able to solve also by setting the environment variable MSBuildSDKsPath to point to the latest sdks folder (in my case, C:\Program Files\dotnet\sdk\2.1.500\Sdks)

damianpawski commented 5 years ago

Having the same issue on Windows 10, setting up the MSBuildSDKsPath did not work for me. I am using SDK 2.1.500

ThisDevDane commented 5 years ago

This happens on my system too, I'm running Manjaro (Arch)

high-on-communism commented 5 years ago

Another sad user of Manjaro having the same issue over here...

trejjam commented 5 years ago

I had the same issue in Rider, I solve it configuring .Net binary as /opt/dotnet/dotnet. Configuring MSBuildSDKsPath didn't help

boumanb commented 5 years ago

I am running Manjaro (Arch) Following fixed it for me:

export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
sudo -E bash -c 'echo $MSBuildSDKsPath'
marchy commented 5 years ago

Fixed in Mono 5.18.0.

Thanks guys!

CarlosJader commented 5 years ago

I got almost the same error as described. I'm on Win7. After a long time I'm back to learning Unity, got very upset cause I was used to MonoDevelop, it worked greatly. I spent all day trying to make autocomplete work properly. Tried Visual Studio, Sublime3 and Visual Studio Code, or autocomplete wouldn't work at all or it just worked for a couple of seconds... I understand things had to change but I think they should have planned it better, would be cool to have a built-in editor, like installed together with Unity and really read to go. I'm pretty sure it's trivial for experienced users but for a new student, to struggle to do something that should be simple work correctly is highly discourageous... As suggested I'm downloading the Mono 5.18.0 Preview version right now, hope it works.

Edit:

Installing Mono 5.18.0 didn't work for me.

This is the entire output:

Starting OmniSharp server at 12/31/2018, 10:37:06 AM Target: c:\Unity\Projects\Survival Shooter\Survival Shooter\Survival Shooter.sln

OmniSharp server started. Path: C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\OmniSharp.exe PID: 10032

    Starting OmniSharp on Windows 6.1.7601.65536 (x64)
    DotNetPath set to dotnet
    Located 1 MSBuild instance(s)
        1: StandAlone 15.0 - "C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
    MSBUILD_EXE_PATH environment variable set to 'C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin\MSBuild.exe'
    Registered MSBuild instance: StandAlone 15.0 - "C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin"
        CscToolExe = csc.exe
        CscToolPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin\Roslyn
        MSBuildExtensionsPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild
        MSBuildToolsPath = C:\Users\Win 7\.vscode\extensions\ms-vscode.csharp-1.17.1\.omnisharp\1.32.8\msbuild\15.0\Bin
    Detecting Cake files in 'c:\Unity\Projects\Survival Shooter\Survival Shooter'.
    Could not find any Cake files
    Project system 'OmniSharp.DotNet.DotNetProjectSystem' is disabled in the configuration.
    Detecting projects in 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Survival Shooter.sln'.
    Queue project update for 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj'
    Queue project update for 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj'
    Detecting CSX files in 'c:\Unity\Projects\Survival Shooter\Survival Shooter'.
    Loading project: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj
    Could not find any CSX files
    Invoking Workspace Options Provider: OmniSharp.Roslyn.CSharp.Services.CSharpWorkspaceOptionsProvider
    Configuration finished.
    Omnisharp server running using Stdio at location 'c:\Unity\Projects\Survival Shooter\Survival Shooter' on host 9196.
    The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
    Failed to load project file 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj'.

c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\msbuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

    Loading project: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj
    The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
    Failed to load project file 'c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj'.

c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj C:\Users\Win 7.vscode\extensions\ms-vscode.csharp-1.17.1.omnisharp\1.32.8\msbuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1126,5): Error: The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.

    Attemped to update project that is not loaded: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp.csproj
    Attemped to update project that is not loaded: c:\Unity\Projects\Survival Shooter\Survival Shooter\Assembly-CSharp-Editor.csproj

The csproj files are there, it just can't see them.

This part cought my attention since I have .NET v4.7.2 installed. "The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed." Couldn't install v4.5 nor uninstall v4.7.2 (tried uninstalling lots of times, uninstalling ends, it says its gone, but its always there, restarted pc several times after uninstalling and its always the same)

I'm noob but if I understood correctly there should be a way to target app to my .NET version? If so, how can I do that? (I'm using VSCode)

evs-chris commented 5 years ago

I can confirm that setting MSBuildSDKsPath resolved the issue for me on Ubuntu 18.04 using the dotnet-sdk snap. For those using the snap, it might be easier to just let the dotnet bin fill in the base path:

export MSBuildSDKsPath=`dotnet --info | grep 'Base Path' | sed -re 's/[^\/]*(.*)/\1/g'`/Sdks

which, I'd guess would work just fine for non-snap versions of dotnetcore.

rchande commented 5 years ago

@CarlosJader I don't think the problem you're encountering is related to this one. Please file a new issue so we can help you troubleshoot.

flaviotsales commented 5 years ago

I'm using Manjaro and setting MSBuildSDKsPath dit not solve the issue. What did solve the issue for me was copying ths Sdks folder to mono/msbuild/15.0/bin, in my case, cp -r /opt/dotnet/sdk/2.2.103/Sdks /usr/lib/mono/msbuild/15.0/bin After that, OmniSharp complained about the NugetFallbackFolder, which I created in /opt/dotnet/sdk. mkdir /opt/dotnet/sdk/NugetFallbackFolder Now OmniSharp doens't complain about anything and I can build my projects appropriately.

Charly6596 commented 5 years ago

~~I'm running Manjaro, the MSBuildSDKsPath solution didn't work for me, nor installing msbuild-stable, but cp -r /opt/dotnet/sdk/2.2.103/Sdks /usr/lib/mono/msbuild/15.0/bin worked, doesn't seem a proper solution.. but it works :man_shrugging:~~ EDIT: the MSBuildSDKsPath solution worked, read what @ehouarn-perret said below if you're having issues

natalie-o-perret commented 5 years ago

@Charly6596 actually the solution given by @anticide works: export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks

But you have to persist that change for every new bash instance, therefore you can put that at the end of your .bashrc file along with what is needed for the local self-signed certificate (for proper https support in your local environment):

export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks
export PATH="$PATH:/home/manjaro/.dotnet/tools"

I managed to have everything working with a Manjaro 18.02 Gnome edition on a live session. I had some other prior issues to that one: https://github.com/OmniSharp/omnisharp-vscode/issues/2837

Baby steps (similar to my other issue resolution in the link above)

Charly6596 commented 5 years ago

@ehouarn-perret Thanks a lot, I fixed it with the following steps,

natalie-o-perret commented 5 years ago

@Charly6596 glad to know that my solution could help you out

natalie-o-perret commented 5 years ago

Playing over and over I've noticed that the insiders is not necessary: I explain everything here, in my SO answer update:

[UPDATE] The official Visual Code AUR page shows the different versions available:

The following packages provide VSCode:

  • code (open-source release)
  • visual-studio-code-bin AUR (Microsoft-branded release)
  • code-git AUR (in-development open-source version)

I think I may have had installed the wrong version at first (the non insiders one was the open source release: code.

Actually when playing with the official tar.gz from the website (which is the hard way equivalent of installing visual-studio-code-bin) it worked fine.

The right way is to (obviously) go with the official Microsoft branded release: visual-studio-code-bin.

natalie-o-perret commented 5 years ago

Does not work anymore after the last update: https://aur.archlinux.org/packages/visual-studio-code-bin

nguerrera commented 5 years ago

@akoeplinger @marek-safar Are there distributions of mono that include msbuild, but not Microsoft.DotNet.MSBuildSdkResolver?

nguerrera commented 5 years ago

I'd like to get to the bottom of why folks are resorting to setting MSBuildSdksPath. See https://github.com/dotnet/cli/issues/10865. They end up breaking themselves with every SDK update. This should not be necessary as I've explained in https://github.com/OmniSharp/omnisharp-vscode/issues/2604#issuecomment-430330103.

EDIT: https://github.com/dotnet/cli/issues/10865 was on Windows so was probably set for a different reason, but I'm still curious about why folks are needing to set this on some Linux installations.

marek-safar commented 5 years ago

Are there distributions of mono that include msbuild, but not Microsoft.DotNet.MSBuildSdkResolver?

@radical ?

radical commented 5 years ago

@directhex might be able to answer this.

directhex commented 5 years ago

Yes: RHEL 6.

There are three pieces in play: Microsoft.DotNet.MSBuildSdkResolver.dll (from msbuild.git), libhostfxr.so (from core-setup.git), and the rest of msbuild.git. The package dependency chain is msbuild :arrow_right: msbuild-libhostfxr :arrow_right: msbuild-sdkresolver

In the case of our RHEL/CentOS 6 repository, the msbuild-libhostfxr package is intentionally empty (because it cannot compile, because the available version of g++ is too old), and does not depend on msbuild-sdkresolver since it's not functional without libhostfxr.so

I haven't re-examined this mess since 2017, maybe things have changed since then to allow the relevant library to compile with RHEL 6's neolithic g++. It's using a git snapshot of core-setup from 2017-07-06.

ptrwis commented 5 years ago

Setting MSBuildSDKsPath solved my problem on Fedora (vscode, .net core3 p3), but IMO a hint to set it should be added to .net core download page: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-preview3-linux-x64-binaries There are instructions to set PATH and DOTNET_ROOT but there is no advice to set MSBuildSDKsPath. So ultimately:

export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$DOTNET_ROOT
export MSBuildSDKsPath=$DOTNET_ROOT/sdk/$(dotnet --version)/Sdks
CTJansson commented 5 years ago

I seem to be doing this wrong, still not very familiar with arch-based Linux (Antergos) yet, so basically I take this export string and paste it into the terminal and press enter and it should just work? export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks Why I think I'm doing wrong it's because code still telling me the sdks can't be found, would probably need a how-to for dummies. Using visual-studio-code-bin from AUR.

arlomba commented 5 years ago

I seem to be doing this wrong, still not very familiar with arch-based Linux (Antergos) yet, so basically I take this export string and paste it into the terminal and press enter and it should just work? export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks

No, you do need to add that line to your .bash_profile file, then reload it with: source ~/.bash_profile

asdf23 commented 5 years ago

A better solution would be:

export MSBuildSDKsPath=/opt/dotnet/sdk/$(dotnet --version)/Sdks

This way you don't have to update SDK's version.

I'm glad I did this before messing with mono

trinvh commented 4 years ago

Setting MSBuildSDKsPath solved my problem on Fedora (vscode, .net core3 p3), but IMO a hint to set it should be added to .net core download page: https://dotnet.microsoft.com/download/thank-you/dotnet-sdk-3.0.100-preview3-linux-x64-binaries There are instructions to set PATH and DOTNET_ROOT but there is no advice to set MSBuildSDKsPath. So ultimately:

export DOTNET_ROOT=$HOME/dotnet
export PATH=$PATH:$DOTNET_ROOT
export MSBuildSDKsPath=$DOTNET_ROOT/sdk/$(dotnet --version)/Sdks

This solves my issue completely