79614040

Date: 2025-05-09 11:42:24
Score: 0.5
Natty:
Report link

Error description

I had similar issue on:
Windows 11
VS Code 1.98.2
.NET SDK 5.0.408

Error message when running project:

Unable to find the project that contains '{project_location}\Program.cs'

Error message when opening project

2025-05-09 12:49:08.054 [info] Cannot use file stream for [{VSCode install path}\data\extensions\ms-dotnettools.csdevkit-1.19.60-win32-x64\components\CPS\platforms\win32-x64\node_modules\@microsoft\visualstudio-projectsystem-buildhost.win32-x64\Microsoft.VisualStudio.ProjectSystem.Server.BuildHost.runtimeconfig.json]: No such file or directory
Invalid runtimeconfig.json [{VSCode install path}\data\extensions\ms-dotnettools.csdevkit-1.19.60-win32-x64\components\CPS\platforms\win32-x64\node_modules\@microsoft\visualstudio-projectsystem-buildhost.win32-x64\Microsoft.VisualStudio.ProjectSystem.Server.BuildHost.runtimeconfig.json] [{VSCode install path}\data\extensions\ms-dotnettools.csdevkit-1.19.60-win32-x64\components\CPS\platforms\win32-x64\node_modules\@microsoft\visualstudio-projectsystem-buildhost.win32-x64\Microsoft.VisualStudio.ProjectSystem.Server.BuildHost.runtimeconfig.dev.json]

2025-05-09 12:49:08.773 [info] Project system initialization finished. 0 project(s) are loaded, and 1 failed to load.

Solution

Solution was to install .NET 5 and .NET 9 SDKs in the same location and start project with selection of .NET version

  1. Steps install VS Code if you don't have it yet
  2. Install Vs Code extension C# Dev kit.
    more: VS Code C Sharp get started
    Do not follow setps to install .NET from this page
  3. Install .NET 5 and next .NET 9 in the same location.
    I used PowerShell script way.
    More on this: https://learn.microsoft.com/en-us/dotnet/core/install/windows#install-with-powershell
    3.2 Install .NET 5 using PowerShell
    3.3 Install .NET 9 in the same folder using PowerShell
# download script
iwr -outf dotnet-install.ps1 https://dot.net/v1/dotnet-install.ps1

#install Net 5
.\dotnet-install.ps1 -Version 5.0.408 -InstallDir DestinationDir

#install Net 9
.\dotnet-install.ps1 -Version 9.0.203 -InstallDir DestinationDir

Note: If you don't specify destrination dir default one will be used.

Check if installation is ok:

dotnet --version

# example output
9.0.203

Check if all versions installed sdks and runtimes are available.

dotnet --list-sdks

# example output
5.0.408 [C:\Users\user\AppData\Local\Microsoft\dotnet\sdk]
9.0.203 [C:\Users\user\AppData\Local\Microsoft\dotnet\sdk]

Usage

Creation of new project with such setup

# make project folder and navigate in

mkdir project_folder
cd project_folder

# Create global.json in project folder with specified .NET version

dotnet new globaljson --sdk-version 5.0.408 --force

# Create project - console example

dotnet new console

Sources

Inspiration to this solution was this article: Dotnet Core Binaries and multiple SDK installations

Similar discussion: https://github.com/microsoft/vscode-dotnettools/issues/789

Reasons:
  • Blacklisted phrase (1): this article
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: PawDob