microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
212 stars 83 forks source link

MsBuildLocator.RegisterDefaults() fails with .NET 7 Preview 7 sdk #168

Closed deepchoudhery closed 1 year ago

deepchoudhery commented 1 year ago

Get the following error message:

No instances of MSBuild could be detected.\r\nTry calling RegisterInstance or RegisterMSBuildPath to manually register one. at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()

Used MSBuildLocator.QueryVisualStudioInstances() to see if any visual studio instances were found but empty.

Not an issue with previous .NET 7 preview sdks and also not an issue if another SDK is installed (.NET 7 Preview or .NET 6). Only an issue if this newest .NET 7 Preview 7 sdk is used standalone.

Also tried to pass the MSBuild.exe path using MSBuildLocator.RegisterMSBuildPath and passed the MSBuild.exe from the installed solo VS instance and that seemed to have no issues.

dotnet --info
.NET SDK:
 Version:   7.0.100-preview.7.22370.3
 Commit:    dbdda95142

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.22000
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100-preview.7.22370.3\

Host:
  Version:      7.0.0-preview.7.22369.4
  Architecture: x64
  Commit:       db5d4dfd16

.NET SDKs installed:
  7.0.100-preview.7.22370.3 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0-preview.7.22369.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0-preview.7.22369.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0-preview.7.22369.18 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]

Environment variables:
  Not set

global.json file:
  C:\scaffolding\global.json

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

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

Used in the dotnet/Scaffolding codebase here

rainersigwald commented 1 year ago

You only have a .NET 7 SDK installed, and it can't be used by an app running on the .NET 6 runtime, because the SDK uses features of the new runtime. You may wish to configure your app for major-version runtime rollforward so that it runs on the highest runtime version available to avoid this, or target your app to net7.0.

deepchoudhery commented 1 year ago

Hmm reread your comment. Will investigate a lil bit and get back to you.

deepchoudhery commented 1 year ago

Closing. Makes sense but since removed dependency for MsBuildLocator.