Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2019 - MSBuild SdkResolver fails to run when using C#

I'm trying to get started with c# (I've been using VS for C++ without issue) and whenever I try to open a C# Project I get this error:

The project file cannot be opened. The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed to run. Illegal characters in path.

The .csprj only has 7 lines!

    <Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

</Project>

I tried swapping the " for ' but got the same error.

Running VS2019 with /ResetSkipPkgs prevents this issue from happening and the project loads fine. However I can't find the source of the issue.

Does anyone else know what could be causing this? I'd like to be able to work on C# projects without running VS via commandline every time!

like image 755
James Kelly Avatar asked Jan 25 '23 18:01

James Kelly


1 Answers

Does anyone else know what could be causing this? I'd like to be able to work on C# projects without running VS via commandline every time!

Not sure what you did to your VS before. Maybe this issue is caused by some third party integration tools, vs extensions, or some VS Settings.

Suggestion

Please try the following steps:

1) make sure that your VS2019 has installed these two workloads

enter image description here

2) check System Environment Variable PATH and make sure that it has value C:\Program Files\dotnet\ and no other space keys.

Also, check if you have environment variable MSBuildSDKsPath, if so, you should check if its value exists and enter the path to check it. If not, you should modify to use the address that already exists.

If MSBuildSDKsPath does not exist, you should add it and set its value to

C:\Program Files\dotnet\sdk\3.1.xxx\Sdks

Make sure the path exists under your PC.

enter image description here

VERY IMPORTANT: Don't use quotes in the variable value and finish it with a \. So please check every environment and make sure that there are no garbled characters.

3) open VS IDE, click menu Extensions-->Manage Extensions and enter into installed extensions and then disable any third party extensions to check whether the issue is caused by them.

4) Reset all VS settings by Tools-->Import and Export Settings-->Reset All Settings or just run devenv /Resetsettings.

5) repair VS or update it to the latest version if there is any updates.

6) delete the .vs hidden folder under the solution folder, bin and obj folder and then test again.

================================================

Besides, you can directly add the switch into /ResetSkipPkgs into VS icon so that every time when you open VS, it will run the /ResetSkipPkgs at the same time.

Right-click on the VS2019 Shortcut icon-->Properties-->Shortcut

enter image description here

Add /ResetSkipPkgs into the

enter image description here

Click Apply and Ok to enable it.

Note: when you use it, you should open VS by clicking that icon rather than start it under VS Installer which does not support that feature).

If you start VS2019 in Start Menu, you should modify the Shortcut by my function in C:\ProgramData\Microsoft\Windows\Start Menu\Programs.

like image 185
Mr Qian Avatar answered Feb 02 '23 07:02

Mr Qian