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

InvalidOperationException: No instances of MSBuild could be detected. #489

Open
ebaker-sogeti opened this issue Feb 18, 2025 · 4 comments
Open

Comments

@ebaker-sogeti
Copy link

Describe the bug

When following the Community Toolkit instructions for SQL Database Projects I consistently run into issues with MSBuild not being available.

Regression

No response

Steps to reproduce

1. Environment: Visual Studio 2022 Pro, .NET 8.0, Aspire 9.0. 
2. Create new .NET Aspire Starter App (Blazor front end, API backend service)
3. `dotnet tool install -g microsoft.sqlpackage`
4. `dotnet new -i Microsoft.Build.Sql.Templates`
5. `dotnet new sqlproj -n ProductsTutorial`
6. Solution > Add Existing > ProductsTutorial.sqlproj
7. Add .sqlproj reference to AppHost project
8. Add `CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects` nuget package to AppHost
9. AppHost Program.cs code:

var builder = DistributedApplication.CreateBuilder(args);

var sql = builder.AddSqlServer("sql")
                 .AddDatabase("test");

builder.AddSqlProject<Projects.ProductsTutorial>("mysqlproj")
       .WithReference(sql);

var apiService = builder.AddProject<Projects.AspireApp3_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp3_Web>("webfrontend")
    .WithExternalHttpEndpoints()
    .WithReference(apiService)
    .WaitFor(apiService);

builder.Build().Run();


10. Start/debug project
11. Error received

When commenting out builder.AddSqlProject the app starts and works as expected. The sqlproj project also works independently if I schema compare or apply changes to the SQL Server created by Aspire. 

System.TypeInitializationException: 'The type initializer for 'Aspire.Hosting.SqlProjectBuilderExtensions' threw an exception.'
InvalidOperationException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one

Expected behavior

I would expect a SQL Server container to be created with a default database and a dacpac applied to the instance

Screenshots

Image

IDE and version

VS 2022

IDE version

17.13.0

Nuget packages

AppHost:
Aspire.Hosting.AppHost (9.0.0)
CommunityToolkit.Aspire.Hosting.SqlDatabaseProjects (9.1.0)

Additional context

No response

Help us help you

Yes, but only if others can assist

@aaronpowell
Copy link
Member

@ErikEJ @jmezach

@ErikEJ
Copy link
Contributor

ErikEJ commented Feb 19, 2025

@ebaker-sogeti Could be your VS or .NET SDK install that is broken, to to re-install the .NET 8 SDK and repair VS.

@jmezach
Copy link
Contributor

jmezach commented Feb 19, 2025

Looking at the docs for MSBuild.Locator, which is what we're using to find MSBuild so we can load the project file, there are a bunch of environment variables that it is looking for. Perhaps none of them are set in your environment, causing these errors? See https://github.com/microsoft/MSBuildLocator?tab=readme-ov-file#how-locator-searches-for-net-sdk

@ebaker-sogeti
Copy link
Author

@ebaker-sogeti Could be your VS or .NET SDK install that is broken, to to re-install the .NET 8 SDK and repair VS.

Thanks Erik - I went through and repaired Visual Studio and also uninstalled .NET 8 components, .NET Aspire SDK, and MSBuild and I am still seeing the same thing.

Image

Image

Image

Image

@jmezach I am going to review this list in the afternoon, thank you for the suggestion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants