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

[BUG] Projects failed to load after installing c# Dev Kit #367

Closed
Tracked by #492
chemari opened this issue Aug 9, 2023 · 39 comments
Closed
Tracked by #492

[BUG] Projects failed to load after installing c# Dev Kit #367

chemari opened this issue Aug 9, 2023 · 39 comments
Assignees
Labels
area-project-cps area-unity Unity support bug Something isn't working mac MacOS
Milestone

Comments

@chemari
Copy link

chemari commented Aug 9, 2023

Describe the Issue

After installing C# Dev Kit in my Mac, and opening an Unity project, I receive this error in the console

image

"Project system initialization finished. 0 project(s) are loaded, and 49 failed to load."

There are no error descriptions in the console or any clue that could lead me to a solution, so couldnt get any info why this is happening. But since then I cannot navigate through "Go to definition", "Go to references", etc. The red underline compilation errors also disappeared from the editor!

Steps To Reproduce

  1. The project Im opening is an Unity 2021.3 project, in Unity I have the extension Visual Studio Editor 2.0.20
  2. Open VS code 1.81 in Mac
  3. Install C# Dev Kit 0.3.21 and let the project load
  4. Check the console (project) output

Expected Behavior

No response

Environment Information

No response

@chemari chemari added the bug Something isn't working label Aug 9, 2023
@microsoft-issue-labeler microsoft-issue-labeler bot added the area-project Project load, Solution Explorer label Aug 9, 2023
@AzuStar
Copy link

AzuStar commented Aug 9, 2023

Before anyone comments.
Pre-release versions of (C#, C# devkit) do not help. Forcing C# to use omnisharp: true and moderndotnet: flase also doesn't help.
This is a duplicate of #337, #335

@jbevain
Copy link
Member

jbevain commented Aug 9, 2023

Hi! Based on your error, it looks like VS Code is trying to open a solution containing old csproj files that are not supported by the C# Dev Kit. You can verify it by opening a .csproj, if they start with:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Then that's what is causing the issue.

  • You've already upgraded the Visual Studio Editor package in Unity to 2.0.20,
  • Delete all .csproj and all .sln files in the root folder of your Unity project,
  • In Unity's preferences, make sure Visual Studio Code is selected as your External Editor,
  • Press Regenerate Project files.

The .csproj files should now start with:

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

And the C# Dev Kit should now be able to open the solution.

@chemari
Copy link
Author

chemari commented Aug 9, 2023

Hi, @jbevain, I followed all the steps you mention, and after this I made sure the header of my csproj files is this:

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

Unfortunately the problem persists in my computer. However that fix worked for one of my colleagues.

@jtsom
Copy link

jtsom commented Aug 9, 2023

I am seeing this also, and am seeing this error when looking at the Solution Explorer under each project:
image

The only thing I haven't tried - I had updated Visual Studio to the latest Preview version (Version 17.8.0 Preview 1.0) and it looks like it installed a preview version of .NET 8:
image

Adding a global.json file, locking to a previous version (7.0.307) showed a message about requiring a different version of the C# runtime/library or something). Reloading the window and the projects loaded up again.

image

Sounds like the C# Dev Kit is not compatible with .NET 8 preview.

@chemari
Copy link
Author

chemari commented Aug 9, 2023

In my case I am using .NET 7
This is the full output of the project:

2023-08-09 16:04:56.154 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.203
 Commit:    5b005c19f5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.203/

Host:
  Version:      7.0.5
  Architecture: x64
  Commit:       8042d61b17

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

2023-08-09 16:04:56.154 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.203
 Commit:    5b005c19f5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.203/

Host:
  Version:      7.0.5
  Architecture: x64
  Commit:       8042d61b17

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

2023-08-09 16:05:01.023 [info] Project system initialization finished. 0 project(s) are loaded, and 49 failed to load.

@jbevain
Copy link
Member

jbevain commented Aug 9, 2023

Thanks for reporting this. You're the second one on macOS 10.15/x64 reporting a similar issue, we're trying to see if we can reproduce it.

@jtsom
Copy link

jtsom commented Aug 9, 2023

FYI.. my issue is on Windows 11.

@AzuStar
Copy link

AzuStar commented Aug 9, 2023

@jbevain would be nice if we could force logger to log everything (trace level or something), but all the logs we get are literally
[Info] Loaded 0 projects, failed to load XX projects which is not exactly self-explaining.

@tmitchel2
Copy link

I have this issue. I looked into the extension logs and found this.

[exthost/ms-dotnettools.csdevkit/ServiceHub/FA474B2D-Microsoft.VisualStudio.ProjectSystem.CompositionService-9528-gwcjacua-1.log]

08/10/2023 10:03:58 Greenwich Mean Time: Error : 9528 :!!Resolve NET Core SDK: Failed
System.DllNotFoundException: Unable to load shared library 'hostfxr' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable:
dlopen(/usr/local/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/hostfxr.dylib, 1): image not found
dlopen(/Users/tmitchel2/.vscode/extensions/ms-dotnettools.csdevkit-0.4.2-darwin-x64/components/CPS/platforms/darwin-x64/node_modules/@microsoft/visualstudio-projectsystem-buildhost.darwin-x64/hostfxr.dylib, 1): image not found

Which in turn relates to this issue in the MSBuildLocator
microsoft/MSBuildLocator#210

@yuhuihu
Copy link

yuhuihu commented Aug 10, 2023

In my case I am using .NET 7 This is the full output of the project:

2023-08-09 16:04:56.154 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.203
 Commit:    5b005c19f5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.203/

Host:
  Version:      7.0.5
  Architecture: x64
  Commit:       8042d61b17

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

2023-08-09 16:04:56.154 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.203
 Commit:    5b005c19f5

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.203/

Host:
  Version:      7.0.5
  Architecture: x64
  Commit:       8042d61b17

.NET SDKs installed:
  5.0.302 [/usr/local/share/dotnet/sdk]
  7.0.203 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

2023-08-09 16:05:01.023 [info] Project system initialization finished. 0 project(s) are loaded, and 49 failed to load.

The same issue.

Also mac 13.4.1

@yuhuihu
Copy link

yuhuihu commented Aug 10, 2023

I fixed it by add configuration to setting.json

"dotnetAcquisitionExtension.existingDotnetPath": [
        {
            "extensionId": "ms-dotnettools.csdevkit",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId": "ms-dotnettools.csharp",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId": "msazurermtools.azurerm-vscode-tools",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId":"visualstudiotoolsforunity.vstuc",
            "path": "/usr/local/share/dotnet/dotnet"
        }
    ],

@chemari
Copy link
Author

chemari commented Aug 10, 2023

Hi @yuhuihu I tried to add your snippet of code to my settings.json and restart VS, but didnt fix the problem in my case :(

In case it helps, this is my entire settings.json content:

{
    "omnisharp.useGlobalMono": "always",
    "files.exclude": {
        "**/*.meta": true
    },
    "omnisharp.enableRoslynAnalyzers": true,
    "omnisharp.organizeImportsOnFormat": true,
    "omnisharp.path": "latest",
    "omnisharp.useModernNet": false,
    "editor.inlineSuggest.enabled": true,
    "dotnet.completion.showCompletionItemsFromUnimportedNamespaces": true,
    "workbench.colorTheme": "Visual Studio 2019 Dark",
    "dotnetAcquisitionExtension.existingDotnetPath": [
        {
            "extensionId": "ms-dotnettools.csdevkit",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId": "ms-dotnettools.csharp",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId": "msazurermtools.azurerm-vscode-tools",
            "path": "/usr/local/share/dotnet/dotnet"
        },
        {
            "extensionId":"visualstudiotoolsforunity.vstuc",
            "path": "/usr/local/share/dotnet/dotnet"
        }

    ]
}

@xMoRoZoKx
Copy link

i have this problem in windows 11((

@xMoRoZoKx
Copy link

also this problem is observed in all my colleagues, with windows version 10/11

@firekim2
Copy link

firekim2 commented Aug 12, 2023

In my case, I found a reason with the .net SDK version.
I installed .net sdk with brew which only support upto 7.0.100 version and seems like not supported with c# dev kit.
After removing dotnet in brew, I updated to 7.0.400 with binary installation and it works now.

Also try to set ~/global.json,

{
  "sdk": {
    "version": "7.0.400"
  }
}

https://learn.microsoft.com/en-us/dotnet/core/install/macos
I followed this!

I'm really glad it finally start to work....!

@webreidi webreidi added this to the GA milestone Aug 16, 2023
@roboriaan
Copy link

I partially solved the issue by reinstalling the C# Devkit. All projects are loading but no code navigation works (F12). That's a biggy for me. Just as a test I loaded the solution up in Visual studio 2022. Works there but not in vscode. Been long enough with MS vscode tools to tell you this is a trend. Almost feels intentional.

@eastedgeZack
Copy link

Also seeing this problem on Mac Big Sur

@webreidi webreidi added the mac MacOS label Aug 16, 2023
@symbion6
Copy link

Also seeing this problem. Running VS Code on an Intel Core i7 MacBook with MacOS 11.3.

  • Re-installed .Net Core from this link: https://dotnet.microsoft.com/en-us/download
  • Re-installed VS Code
  • Added the C# Dev Kit extension
  • Added the global.json as per @firekim2 's recommendation.
  • Loaded my project, double checked the first line of the .csproj file, which is OK

This is the log:

2023-08-17 11:05:56.569 [info] Project system initialization finished. 0 project(s) are loaded, and 2 failed to load.
2023-08-17 11:05:56.658 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.400
 Commit:    73bf45718d

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  11.3
 OS Platform: Darwin
 RID:         osx.11.0-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.400/

Host:
  Version:      7.0.10
  Architecture: x64
  Commit:       a6dbb800a4

.NET SDKs installed:
  7.0.400 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  /Users/myusername/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download


@tmeschter
Copy link
Member

@symbion6 When you run into this problem, would you be able to run "Developer: Open Extension Logs Folder" from the command palette, and then zip up and share the "ms-dotnettools.csdevkit" folder? I suspect an error message about this issue may be buried there.

@SimeonIksanov
Copy link

ms-dotnettools.csdevkit.zip
same problem

@chemari
Copy link
Author

chemari commented Aug 18, 2023

Thanks @firekim2, unfortunately it didnt work. I updated to 7.0.400 (and removed the older version) and added the global.json file, but I keep getting the same error.

2023-08-18 11:35:41.687 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
 Version:   7.0.400
 Commit:    73bf45718d

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.15
 OS Platform: Darwin
 RID:         osx.10.15-x64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.400/

Host:
  Version:      7.0.10
  Architecture: x64
  Commit:       a6dbb800a4

.NET SDKs installed:
  7.0.400 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 5.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  /Users/jxxx/global.json

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

2023-08-18 11:35:43.594 [info] Project system initialization finished. 0 project(s) are loaded, and 48 failed to load.

@chemari chemari closed this as completed Aug 18, 2023
@chemari chemari reopened this Aug 18, 2023
@YoungXiang
Copy link

YoungXiang commented Aug 18, 2023

Having the same issue with Unity 2018.4.16.

  • .csproj generated by Unity cannot be loaded by C# dev kit.
  • .Net sdk version is : 7.0.3
  • Can be resolved by adding net7.0 in csproj. But that's not convenient, since the .csproj will be re-generated and override by Unity.

I looked into vs code log folder, and found this:


08/18/2023 15:00:31 中国标准时间: Information : 24116 :SDK folder is resolved to 'C:\Program Files\dotnet\sdk\7.0.306' based on path 'c:\Users\xxx.
08/18/2023 15:00:31 中国标准时间: Information : 24116 :Initialize Project System Service. 196ms.
08/18/2023 15:00:31 中国标准时间: Information : 24116 :Loading project 'c:\Users\xxx.csproj' is vetoed.
08/18/2023 15:00:31 中国标准时间: Information : 24116 :Creating new ConfiguredProject - Name Debug|AnyCPU - for project c:\Users\xxx.csproj
08/18/2023 15:00:31 中国标准时间: Error : 24116 :Error loading project: System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.GetLatestVersionAsync[T](IProjectValueDataSource1 valueSource, IProjectDataSourceRegistryHelper dataSourceRegistryHelper, Func3 linkCreator, IProjectCommonServices services, ImmutableDictionary2 initialVersionRequirements, CancellationToken cancellationToken) at Microsoft.VisualStudio.ProjectSystem.ConfiguredProjectImpl.InitializeAsync(Lazy1 xml, ProjectConfiguration projectConfig, IProjectEvaluationContext projectEvaluationContext, String forcedProjectFullPath)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.LoadConfiguredProjectImplAsync(ProjectConfiguration projectConfiguration, IProjectEvaluationContext projectEvaluationContext)
08/18/2023 15:00:31 中国标准时间: Error : 24116 :Project unload waited on tasks that ended up throwing exceptions. System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.VisualStudio.ProjectSystem.ProjectDataSources.GetLatestVersionAsync[T](IProjectValueDataSource1 valueSource, IProjectDataSourceRegistryHelper dataSourceRegistryHelper, Func3 linkCreator, IProjectCommonServices services, ImmutableDictionary2 initialVersionRequirements, CancellationToken cancellationToken) at Microsoft.VisualStudio.ProjectSystem.ConfiguredProjectImpl.InitializeAsync(Lazy1 xml, ProjectConfiguration projectConfig, IProjectEvaluationContext projectEvaluationContext, String forcedProjectFullPath)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.LoadConfiguredProjectImplAsync(ProjectConfiguration projectConfiguration, IProjectEvaluationContext projectEvaluationContext)
at Microsoft.VisualStudio.ProjectSystem.CommonProjectSystemTools.Rethrow(Exception ex)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.LoadConfiguredProjectImplAsync(ProjectConfiguration projectConfiguration, IProjectEvaluationContext projectEvaluationContext)
at Microsoft.VisualStudio.ProjectSystem.UnconfiguredProjectImpl.<>c__DisplayClass221_1.<b__1>d.MoveNext()
--- End of stack trace from previous location ---

@kvenkatrajan kvenkatrajan added the area-unity Unity support label Aug 21, 2023
@tmeschter
Copy link
Member

@YoungXiang I believe that is a different problem; can you please open a new issue so we can track it properly?

@tmeschter
Copy link
Member

@SimeonIksanov Thank you for the logs; you are indeed seeing the same issue as @tmitchel2.

@tmeschter
Copy link
Member

For those of you experiencing this issue (specifically, the one where hostfxr is not being found) we are actively working on it. The failure is occurring in a code path that attempts to detect the available .NET SDKs; it is challenging to get this to work correctly across all relevant architectures, operating systems, and install methods.

@tmeschter tmeschter self-assigned this Aug 23, 2023
@mgmhunt
Copy link

mgmhunt commented Aug 25, 2023

On Mac this will fix the 'xx project failed to load' (adjust version as necessary)... until the ext is fixed

Copy this file:
/usr/local/share/dotnet/host/fxr/7.0.10/libhostfxr.dylib

To:
/usr/local/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/libhostfxr.dylib

(which is where the extension is looking, thanks to @tmitchel2 for pointing out the log location.)

@jonnymarkd
Copy link

Same issue.

mgmhunt's temp fix (comment above) doesn't work for me. I don't have the ...Microsoft.NetCore.App/ folder...

Output as follows:

2023-08-27 23:11:32.380 [info] Additional information of .NET SDKs for diagnostic.NET SDK:
Version: 7.0.400
Commit: 73bf45718d

Runtime Environment:
OS Name: Mac OS X
OS Version: 11.6
OS Platform: Darwin
RID: osx.11.0-x64
Base Path: /usr/local/share/dotnet/sdk/7.0.400/

Host:
Version: 7.0.10
Architecture: x64
Commit: a6dbb800a4

.NET SDKs installed:
3.1.302 [/usr/local/share/dotnet/sdk]
6.0.413 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
7.0.400 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.21 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

2023-08-27 23:11:32.385 [info] Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.

@mgmhunt
Copy link

mgmhunt commented Aug 27, 2023

Same issue.

mgmhunt's temp fix (comment above) doesn't work for me. I don't have the ...Microsoft.NetCore.App/ folder...

Output as follows:

[/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10

jonnymarkd Have you tried right-clicking on the Microsoft.NETCore.App and choosing Show Package Contents? should take you to folder structure

@jonnymarkd
Copy link

Thanks @mgmhunt - Did the trick for me. Now for the ext fix...

@chemari
Copy link
Author

chemari commented Aug 28, 2023

On Mac this will fix the 'xx project failed to load' (adjust version as necessary)... until the ext is fixed

Copy this file: /usr/local/share/dotnet/host/fxr/7.0.10/libhostfxr.dylib

To: /usr/local/share/dotnet/shared/Microsoft.NETCore.App/7.0.10/libhostfxr.dylib

(which is where the extension is looking, thanks to @tmitchel2 for pointing out the log location.)

I tried this. I keep receiveing the same "0 projects loaded 45 failed to load". But now I receive some extra errors I have never seen before. I get one of this for each project:

2023-08-28 14:39:08.772 [error] Failed to load project '/Users/jxxx/Projects/tribes/Unity.PlayerPrefsEditor.Samples.SampleScene.csproj'. One or more errors occurred. (This project is not supported in C# Dev Kit.)

@mgmhunt
Copy link

mgmhunt commented Aug 28, 2023

@chemari sounds like progress actually :) ie generating errors vs not loading at all. Maybe regen the csproj files via Unity Preferences -> External Tools. I'm running the exact setup as you in the original comment.

@kvenkatrajan kvenkatrajan added area-project-cps and removed area-project Project load, Solution Explorer labels Aug 29, 2023
@YuliiaKovalova
Copy link

The issue was addressed in the scope of dotnet/msbuild#9038

You can use the package with the fix https://www.nuget.org/packages/Microsoft.Build.Locator/1.6.1.

@zihli
Copy link

zihli commented Aug 31, 2023

I had the same issue on macOS Big Sur. I updated OS to Monterey and it works now.

@lifengl
Copy link
Member

lifengl commented Sep 6, 2023

there are multiple different issues in this thread:
1, a common problem, the extension cannot resolve SDK on macOS Big Sur. The same issue happens with SDK installed with HomeBrew, and also it hits some Linux distributions. That problem, as Yullia mentioned, should be fixed when the next pre-release update comes out in a few days.

2, traditional unity projects, (or other traditional mono projects or Framework projects on windows) those are currently not supported by C# Dev Kit, but some pending fix in this area would allow language experience to work. It is still on-going work.

3, extension was broken when NET 8 preview 7 was out. it was a gap between multiple product line due to the extension runs on NET 7 runtime loads build related assemblies from SDK, which were updated to build on NET 8 runtime. During initialization, this corrupted a cache file, which lead it tricky to apply a workaround (that is why some people might not get it to work with a global.json file, but some might not be able to) This issue should have been addressed with a later update.

@JMBartelt
Copy link

JMBartelt commented Sep 7, 2023

This post from Unity solved my issues:
https://forum.unity.com/threads/microsoft-previews-unity-extension-for-visual-studio-code.1468913/

  • You need Unity 2021 or higher and the "Visual Studio Editor" package version 2.0.20 or above installed in your Unity project.
  • Remove any old, deprecated VS Code packages from Unity. Install the new Unity Extension in Visual Studio Code, which will also install necessary dependencies like the C# Dev Kit.
  • Set Visual Studio Code as your external script editor in Unity Editor under External Tools.
  • Regenerate Project Files

@CrisViM
Copy link

CrisViM commented Sep 12, 2023

This post from Unity solved my issues: https://forum.unity.com/threads/microsoft-previews-unity-extension-for-visual-studio-code.1468913/

  • You need Unity 2021 or higher and the "Visual Studio Editor" package version 2.0.20 or above installed in your Unity project.
  • Remove any old, deprecated VS Code packages from Unity. Install the new Unity Extension in Visual Studio Code, which will also install necessary dependencies like the C# Dev Kit.
  • Set Visual Studio Code as your external script editor in Unity Editor under External Tools.
  • You can also get the latest Unity Extension for VS Code

It worked for me. Thank's a lot!

@jbevain
Copy link
Member

jbevain commented Sep 14, 2023

Hi,

At this point we believe the C# and C# Dev Kit have pushed a fix for the loading issue, so we're going to close this issue. Please make sure both extensions are up to date and you've followed the README of the Unity extension:

  • In Unity, you need to upgrade the Visual Studio Editor package to 2.0.20 or above (the latest is 2.0.21)
  • Select Visual Studio Code as the External Editor.
  • Regenerate Project Files

Because this issue evolved with multiple different issues, if you hit more loading issues please open a new one.

Thank you!

@jbevain jbevain closed this as completed Sep 14, 2023
@AmineAndam04
Copy link

Hi.
The same thing happened to me. I updated the Visual Studio Editor package at the Package Manager and this solved the issue for me.

@aoshfan
Copy link

aoshfan commented Jun 30, 2024

Hi! Based on your error, it looks like VS Code is trying to open a solution containing old csproj files that are not supported by the C# Dev Kit. You can verify it by opening a .csproj, if they start with:

<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Then that's what is causing the issue.

  • You've already upgraded the Visual Studio Editor package in Unity to 2.0.20,
  • Delete all .csproj and all .sln files in the root folder of your Unity project,
  • In Unity's preferences, make sure Visual Studio Code is selected as your External Editor,
  • Press Regenerate Project files.

The .csproj files should now start with:

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

And the C# Dev Kit should now be able to open the solution.

This kind of similar fix for me.

but my place need to change was in .sln file.
In the file I just need to fix the location of my .csproj. file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-project-cps area-unity Unity support bug Something isn't working mac MacOS
Projects
None yet
Development

No branches or pull requests