In a tool written with C# (.NET6) I want to access the project file (csproj) of another project (also .NET6).
For this I have referenced the NuGet package Microsoft.Build (17.9.5)
In this library there is the type Project that normally is able to read The projects (csproj) file of the corresponding project.
Project p = new Project(path to project file);
Unfortunately, I always get the following exception.
Could not load file or assembly 'Microsoft.Build.Framework, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
at Microsoft.Build.Evaluation.ProjectCollection..ctor
at Microsoft.Build.Evaluation.ProjectCollection.get_GlobalProjectCollection()
at Microsoft.Build.Evaluation.Project..ctor(String projectFile)
at TestMsBuildApp.Program.Main() in d:\Dev\Experiments\WPFAnalyzer\TestMsBuildApp\Program.cs:line 18
**Question: What is wrong with this procedure?
.NET SDKs installed: 6.0.420 [C:\Program Files\dotnet\sdk] 7.0.314 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Does anyone have an idea?
I tried the following 1.I reinstalled the .NET SDK 2.Restarted Visual Studio 3.Restarted whole machine 3.I created a smal sample solution 4.I tried other classes like (ProjectCollecionInstance.LoadProjects)