Reputation: 63
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!
Upvotes: 6
Views: 9065
Reputation: 51
The two SDK resolvers that ship with Visual Studio and dotnet CLI are: Microsoft.DotNet.MSBuildSdkResolver and Microsoft.Build.NuGetSdkResolver.
Microsoft.DotNet.MSBuildSdkResolver is what resolves “built in” SDKs like Microsoft.NET.Sdk and Microsoft.NET.Sdk.Web. It first looks for your dotnet CLI (eg C:\Program Files\dotnet\dotnet.exe)
Here is the error message in my case:
System.ArgumentException
HResult=0x80070057
Message=Illegal characters in path.
Source=mscorlib
StackTrace:
at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
at System.IO.Path.Combine(String path1, String path2)
at Microsoft.DotNet.DotNetSdkResolver.EnvironmentProvider.<>c__DisplayClass7_0.<GetCommandPath>b__0(String p)
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.DotNet.DotNetSdkResolver.EnvironmentProvider.GetCommandPath(String commandName)
at Microsoft.DotNet.DotNetSdkResolver.NETCoreSdkResolver.GetDotnetExeDirectory()
You have to check the system variables PATH. Open the Command Prompt (CMD) and type: echo %PATH% and check if there are the Illegal characters in path (")
C:\Program Files\Java\jdk1.8.0_291"\bin;
Open the system variables PATH (for Windows 10 and Windows 8):
In my case there were the quotation marks in java_home path:
JAVA_HOME: "C:\Program Files\Java\jdk1.8.0_291"
PATH: %JAVA_HOME%\bin;
1) You can correct the path by using the short path without quotes C:\PROGRA~1\Java\jdk1.8.0_291
2) Move the following paths C:\Program Files\dotnet\
and C:\Program Files (x86)\dotnet\
up, save and restart the Visual Studio.
Upvotes: 0
Reputation: 23858
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
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.
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
Add /ResetSkipPkgs
into the
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
.
Upvotes: 18