Why can't I compile any of my old or new project? [duplicate] - c#

I just upgraded my visual studio 2019 to latest version 16.8.3 and suddenly I am not able to load any C# project and getting the following error for all .NET core projects:
The project file cannot be opened. Unable to locate the .NET SDK.
Check that it is installed and that the version specified in
global.json (if any) matches the installed version.

Try to edit envrionment Variables.
Right click on This PC -> Properties -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables
Add [install path] C:\Program Files\dotnet\ to the variable path.
Restart visual studio.
If it does not solve this problem, you can refer to this answer.

I found that the path C:\Program Files\dotnet was already in my path but it was ordered below the C:\Program Files (x86)\dotnet entry. By simply moving C:\Program Files\dotnet above C:\Program Files (x86)\dotnet in the list and restarting Visual Studio cleared up the problem.

If there is a global.json file in your solution folder(where *.sln file reside), delete this.

In my case, I had .NET 6 preview but then uninstalled it. After uninstalling, some of my projects won't load. I have all the configurations mentioned above but still won't load the projects. I went to C:\Program Files\dotnet\sdk\ where I found that there still exist a .NET 6 folder which is empty. Deleting that empty .NET 6 folder fixes the issue and I was able to load my projects.

This works for me...
Check first if which .net Core SDK is available in the system.
Step 1: Open Command prompt (CMD) and type dotnet --info
The above image shows no SDK is installed or register
Step 2: Install SDK from https://dotnet.microsoft.com/download/dotnet-core
Done Visual studio works like charm... Verify if its properly installed and register
Above image you can see .net core SDK is registered properly on the system.

I had a similar situation upgrading from VS 2019 to VS 2022, trying to run a dotnet 5.0 solution from VS 2022 (that starts to use dotnet 6.0).
In the PATH env. variable I had both 'C:\Program Files\dotnet' and 'C:\Program Files (x86)\dotnet'. I removed the (x86) one and stopped having that error

Installing missed SDK that the project has built solved the problem
I had a similar issue when I tried to build a net5.0 solution that is not installed on my machine.
In my case, I had VS 2022, and net6.0 installed.
Installing net5.0 SDK solved the problem.
I had only C:\Program Files\dotnet in Path env

I just carefully followed the error message and tried to resolve the problem.
I got below error message:
F:\mypath\ServerlessFunc\ServerlessFunc\ServerlessFunc.csproj : error
: The project file cannot be opened. C:\Program
Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk not found. Check
that a recent enough .NET SDK is installed and/or increase the version
specified in global.json.
I then tried to navigate through
C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk
path which was mentioned in the above error and found that the above path does not exist. This problem could be resolved if I install SDK of version of 6.0. Rather I started using VS-2022.

Related

Could not locate MSBuild instance to register with OmniSharp

I have found many questions about this but non have helped me. I am trying to write c# code and the omnisharp auto complete doesn't work and I get this back from the Omnisharp Log:
OmniSharp server started.
Path: c:\Users\GeorgV.216\.vscode\extensions\ms-dotnettools.csharp-1.24.1\.omnisharp\1.38.3-beta.31\OmniSharp.exe
PID: 11536
[info]: OmniSharp.Stdio.Host
Starting OmniSharp on Windows 6.2.9200.0 (x64)
[info]: OmniSharp.Services.DotNetCliService
Checking the 'DOTNET_ROOT' environment variable to find a .NET SDK
[info]: OmniSharp.Services.DotNetCliService
Using the 'dotnet' on the PATH.
[info]: OmniSharp.Services.DotNetCliService
DotNetPath set to dotnet
[info]: OmniSharp.MSBuild.Discovery.MSBuildLocator
Located 0 MSBuild instance(s)
Could not locate MSBuild instance to register with OmniSharp.
What could be a possible solution?
As of May 2022, Omnisharp does not include MSBuild.
It can be installed with Build Tools for Visual Studio, found at the bottom of this page.
During install select .NET desktop build tools:
More info in this issue.
The solution that worked for me was to change the "omnisharp.path": from "latest" to "" in the setting.json file and delete the 1.38.3-beta.31 folder in C:\Users{username}.vscode\extensions\ms-dotnettools.csharp-1.24.1.omnisharp
If you're using VSCode, a simple fix is to install an older C# extension version.
Extensions -> arrow next to uninstall -> install another version -> v1.24.1
It's a temporary fix as you're stuck with an old version of C# extension but it's a quick and simple one.
Suddenly got this problem too, adding "omnisharp.useModernNet": true to the settings.json fixed it for me.
Working for me now. Maybe the cause is (from omnisharp github):
"Planned removal of the included Mono & MSBuild Tools
In the future .NET Framework builds of OmniSharp will not ship with Mono or the MSBuild tooling (See announcement omnisharp-roslyn#2339). To ensure that the C# extension remains usable out of the box for .NET SDK projects, we will be changing the default value of omnisharp.useModernNet to true."
But " omnisharp.useModernNet to true" does not work with Unity 3d.
So.
I uninstall all dotnets from ubuntu.
Unistall mono.
Reinstall dotnet using this: https://learn.microsoft.com/es-es/dotnet/core/install/linux-ubuntu#2110-
Reinstall mono-complete using synaptics.
And in VS settings set omnisharp using global mono to "always".
Now it's working for me.
The solution that worked for me:
Manage
Settings
search for "omnisharp path"
edit in settings.json
enter code here> replace "latest" with ""
For me runs with
"omnisharp.enableEditorConfigSupport": true,
"omnisharp.path": "latest",
"omnisharp.projectLoadTimeout": 60,
"omnisharp.useGlobalMono": "always",
"omnisharp.useModernNet": true,
on settings.json file....
Omnisharp has been updated to .NET 6.0. The older .NET Framework builds will no longer ship with MSBuild tools (and you don't already have them installed) so that's the reason for your error.
Remove the msbuild error by setting the following in VSCode settings.json:
"omnisharp.path": ""
Upgrade to the newer .NET 6.0 builds of OmniSharp by setting the following:
"omnisharp.useModernNet": true
Quick Solution for every platform (Windows, Linux, Mac)
Set VS Code update mode to 'manual'
Disable Windows Background Updates
Downgrade the VS Code version to February 2022 (version 1.65)
Downgrade the C# extension version to v1.24.4
everything will be fine 💯
#5253 (comment)
Faced with same problem after upgrade to .net 6. In vs code problems with onmnisharp, intelisense and getting this error as well.
Make sure to install mono latest version.
Make sure to install .net 6.0.401 sdk.
If upgrade from .net 5 to .net 6 I suggest to uninstall first .net 5.
Uninstall C# extension from vs code.
Delete "ms-dotnettools.csharp-1.25.0-darwin-arm64" folder from
/Users//.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64
Install C# extension (1.25.0).
Restart Vs code and got to Code>Preferences>Settings
Search for "omnisharp"
Set Logging Level to: trace
Update Dotnet Path (on mac m1): "/usr/local/share/dotnet/dotnet"
Update Mono path: (mac m1): "/Library/Frameworks/Mono.framework/Versions/Current"
Update Sdk Path: "/usr/local/share/dotnet/sdk/6.0.401/"
Update Sdk Version: "6.0.401"
Set User Modern Net: true,
Restart vs code -> check output console.
If you get an error "The .NET Core SDK cannot be located. .NET Core debugging will not be enabled. Make sure the .NET Core SDK is installed and is on the path" continue line 14.
Open "/Users/user/.vscode/extensions/ms-dotnettools.csharp-1.25.0-darwin-arm64/dist/extension.js" this file, and search for this statement:
"args.push(Sdk:Path='${options.sdkPath}');" than remove quotes around curly braces => args.push(Sdk:Path=${options.sdkPath});.
Save all changes and restart vs code. => Now everything should be ok.
Seems that this VsCode extension add quotes, and cause of this its not able to find "sdkPath" specified in the configuration.
This worked for me.
Hope will help someone.
Try installing the older version of C# extension works for me. I downgraded to v1.24.4 and changing one of the line in the setting.json to "omnisharp.useGlobalMono": "always"
I have also noticed that you have to close VS Code completely and reopen to have it working.
I spent at least an hour or two troubleshooting this issue and it seems there are several solutions which work for some but not for others. If you are like me and couldn't find a working solution, this is how I finally got it to work.
I disabled all of my other extensions in VS Code aside from 'C# for VS code' and 'Unity Code Snippets'. I'm not sure which one was the culprit, but I had been using VS Code mainly for JavaScript and I assume the code formatter or live server extensions were interfering somehow with how the .cs was being interpreted. All of a sudden after disabling those, and reloading, it worked. Finally.
If you're using VS Code, a temporary fix is to install an older C# extension version.
Extensions -> install another version -> v1.24.1
it will help as it helped for me.
Here is text from release note for Omnisharp v1.25.0: "Announcement: The C# extension no longer ships with an included Mono & MSBuild Tools". I have installed .Net 6.0 and omnisharp v1.25.0 was able to locate MSBuild from there.
The older version of Omnisharp has MSBuild available within their extension install folder C:\Users\Username.vscode\extensions\ms-dotnettools.csharp-XX.XX.XX....omnisharp\X.XX.XX\msbuild

Microsoft Visual Studio 2019: The project file cannot be opened. Unable to locate the .NET SDK

I just upgraded my visual studio 2019 to latest version 16.8.3 and suddenly I am not able to load any C# project and getting the following error for all .NET core projects:
The project file cannot be opened. Unable to locate the .NET SDK.
Check that it is installed and that the version specified in
global.json (if any) matches the installed version.
Try to edit envrionment Variables.
Right click on This PC -> Properties -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables
Add [install path] C:\Program Files\dotnet\ to the variable path.
Restart visual studio.
If it does not solve this problem, you can refer to this answer.
I found that the path C:\Program Files\dotnet was already in my path but it was ordered below the C:\Program Files (x86)\dotnet entry. By simply moving C:\Program Files\dotnet above C:\Program Files (x86)\dotnet in the list and restarting Visual Studio cleared up the problem.
If there is a global.json file in your solution folder(where *.sln file reside), delete this.
In my case, I had .NET 6 preview but then uninstalled it. After uninstalling, some of my projects won't load. I have all the configurations mentioned above but still won't load the projects. I went to C:\Program Files\dotnet\sdk\ where I found that there still exist a .NET 6 folder which is empty. Deleting that empty .NET 6 folder fixes the issue and I was able to load my projects.
This works for me...
Check first if which .net Core SDK is available in the system.
Step 1: Open Command prompt (CMD) and type dotnet --info
The above image shows no SDK is installed or register
Step 2: Install SDK from https://dotnet.microsoft.com/download/dotnet-core
Done Visual studio works like charm... Verify if its properly installed and register
Above image you can see .net core SDK is registered properly on the system.
I had a similar situation upgrading from VS 2019 to VS 2022, trying to run a dotnet 5.0 solution from VS 2022 (that starts to use dotnet 6.0).
In the PATH env. variable I had both 'C:\Program Files\dotnet' and 'C:\Program Files (x86)\dotnet'. I removed the (x86) one and stopped having that error
Installing missed SDK that the project has built solved the problem
I had a similar issue when I tried to build a net5.0 solution that is not installed on my machine.
In my case, I had VS 2022, and net6.0 installed.
Installing net5.0 SDK solved the problem.
I had only C:\Program Files\dotnet in Path env
I just carefully followed the error message and tried to resolve the problem.
I got below error message:
F:\mypath\ServerlessFunc\ServerlessFunc\ServerlessFunc.csproj : error
: The project file cannot be opened. C:\Program
Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk not found. Check
that a recent enough .NET SDK is installed and/or increase the version
specified in global.json.
I then tried to navigate through
C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk
path which was mentioned in the above error and found that the above path does not exist. This problem could be resolved if I install SDK of version of 6.0. Rather I started using VS-2022.

Intellisense not working in VSCode - OmniSharp Error

Intellisense has stopped working for me and whenever I run VSCode this error comes up in the OmniSharp Log.
[warn]: OmniSharp.MSBuild.ProjectManager
Failed to load project file '/Users/leogaunt/Documents/Programming/Unity/Cube Stack/Assembly-CSharp.csproj'.
/Users/leogaunt/Documents/Programming/Unity/Cube Stack/Assembly-CSharp.csproj
/Users/leogaunt/.vscode/extensions/ms-dotnettools.csharp-1.23.1/.omnisharp/1.37.0/omnisharp/.msbuild/Current/Bin/Microsoft.Common.CurrentVersion.targets(1178,5): Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks
[fail]: OmniSharp.MSBuild.ProjectManager
Attempted to update project that is not loaded: /Users/leogaunt/Documents/Programming/Unity/Cube Stack/Assembly-CSharp.csproj
I have tried re-installing the plugin, and re-intsalling VSCode but it hasn't worked.
I know I have .NET Core installed as I am a Mac user and I know this because when I type dotnet --version in terminal it outputs:
3.1.401
I am programming in Unity and am creating a game for iOS.
Change the mono path to always, in C# extension config.
For anyone that uses VSCode v1.67.2 dotnet v3.x.x and OmniSharp v1.25.0 (or v1.23.17 and above).
The above accepted answer does not solve the issue.
The simplest thing to do is downgrade ms-dotnettools.csharp (C# Extension), the only issue is if you downgrade to any version above v1.23.16 it gives you "Can't install 'ms-dotnettools.csharp' extension because it is not compatible with the current version of Visual Studio Code (version 1.67.2)"
I suggest to downgrade it to version 1.23.16 and restart vscode.
Your Intellisense should start working.
My Environment
dotnet v3.1.417
VSCode v1.67.2
C# Extension v1.25.0 (now downgraded to v1.23.16)
Running in Remote Container on a Mac host.
Yes I am using 3+ year old dotnet version. It's a legacy software, it happens, everyone has skeletons in their systems ;)
Trust me it'll work, tried everything and then came to this
Go into VS code Preferences
Search for omnisharp.path and click on edit in settings.json
Add/edit line "omnisharp.path": "latest" (remember to add a comma at the end of the previous line)
Go back into settings and search omnisharp, scroll down till you find Use Global Mono, change that to Always
After this you will have to download Mono, mac's mono download link is this https://www.mono-project.com/download/stable/#download-mac
After the download finishes, set it up by opening the download file
Go back to settings.json and add mono's /bin path as "omnisharp.monoPath": "/Library/Frameworks/Mono.framework/Versions/6.12.0/bin" which is the default download path for mac, if you wanna confirm this, go into mac's disk space and then follow the above mentioned path)
Finally restart VS Code and it should work (in case it still doesn't, restart it again)
I downgraded the VS Code's C# extension to 1.24.3 from 1.25.0 and it worked.
I had the same Problem after fetching Unity from a git repository.
For me it worked to reset the .Net Version in Unity.
Edit -> Project Settings -> Api Compatibility Level
Switched that back and forth, restarted VSCode. The .csproj-file will file out all the missing dlls.
I solved this by uninstalling all SDK's and installed the older 4.7.1, then everything worked instantly.
I had the same problem. Here's how I fixed it:
I added all projects to the solution file (dotnet sln add <project name>) and opened the project in vs code by passing the path to vscode from terminal
(code <project path>).
The error says that OmniSharp is looking for Version=v4.7.1. You may want to install the latest version of it.

Visual Studio 2019 shows an empty solution after creating a .NET Core project

When I create a new .NET Core project in Visual Studio 2019, it shows only the solution file. Other files are not showing and also I am not able to debug or the project.
I've also run into this problem and after two days of searching forums and reading .NET documentations, I finally managed to find the solution.
The problem is that Visual Studio cannot find the proper SDK version. There might be a few reasons for this, but first of all, check if you have any SDK installed:
Open the Command Prompt:
Start Menu > Visual Studio 2019 > Developer Command Prompt for Visual Studio 2019
Run the command: dotnet --info
Case 1:
The .NET SDKs installed: section says that you have no SDKs installed.
-OR-
A .NET SDK is installed but not for the right architecture (this was my case), meaning that you had installed x86 version instead of x64.
Solution:
Uninstall all versions of .NET Core SDKs and Runtimes, then download and install the latest x64 SDK and Runtime version from Microsoft's webpage.
Case 2:
A .NET SDK is installed but the referenced SDK version in the current project's .csproj file does not match the installed version nor the one specified in the global.json (if exists).
Solution: Edit the .csproj file, so that the SDK versions match.
If you have or need a global.json file, make sure you set its content properly. You can read more about it here.
Finally
Don't forget to open Visual Studio, create a new e.g. Console Application and see if the Solution's files appear in the Solution Explorer window (they should). Note that existing projects may still not be working properly because their .csproj file might have wrong SDK reference - if so, you have to fix them manually.

Can't open or create .NET CORE Web Apps after VS 2K17 Update

I had a previously created web API running under .net core 1.1 and recently I installed .NET Core 2.0. Tired of trying to fix the problem by searching I decided to create a new project running under 2.0 just to realize it does not work either. Had a global.json pointing to 1.0 preview3 two directories upward which I deleted but didn't make a difference. Thanks in advance for any attempt of help provided.
Error presented:
The SDK 'Microsoft.NET.Sdk.Web' specified could not be found"
Running "dotnet --info" on cmd gives me version 2.0.0
Path variables defined (in this order)
C:\Program Files\dotnet\sdk
C:\Program Files (x86)\Microsoft VS Code\bin
C:\Users\FILENGA\AppData\Roaming\npm
%USERPROFILE%\AppData\Local\Microsoft\WindowsApps
Try setting a
global.json
file in the root of your repo setting appropriate SDK.
{
"sdk": {
"version": "1.0.4"
}
}
Then run
dotnet --info
again. If it doesn't say 1.0.4 it isn't correctly taking it.
Make sure you have no other global.json files in the rest of your repo
I had a similar issue and that fixed it. See here
Problem solved. Previous version of VS 2K17 saved projects in a directory other than the most recent. Just had to move old projets to new folder.
I was running into the same issue. I ended up moving c:\program files\dotnot up in my path and it fixed the problem.

Categories

Resources