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
218 stars 83 forks source link

MSBuildLocator finds instance only in net-framework #61

Closed baruchiro closed 5 years ago

baruchiro commented 5 years ago

I try to load a Microsoft.Build.Evaluation.Project in my project. When I compile my project in netcoreapp2.1 the Project didn't loading because MSBuild not loaded.

The code var vsInstances = MSBuildLocator.QueryVisualStudioInstances(); return one instance when it compiled to net471, but return 0 instances when it compiled to netcoreapp2.1.

Maybe it related to #21 or #30, I didn't know. I'm still getting to know the working way and MSBuild's special cases.

baruchiro commented 5 years ago

I see code like this: https://github.com/Microsoft/MSBuildLocator/blob/9c3c8dc23677041b6a23919b14a495dcdd5d7c8d/src/MSBuildLocator/MSBuildLocator.cs#L308-L323

It seems like when we compile with .Net Core we assume that there is no Visual Studio? Or that we don't need to search him?

For my case, I actualy need the Visual Studio when I compile to .Net Core.

baruchiro commented 5 years ago

And if I remove the netcoreapp2.0 from TargetFrameworks in the Microsoft.Build.Locator.csproj, and run the BuilderApp with only netcoreapp, it identifies the VS.

rainersigwald commented 5 years ago

What version of MSBuildLocator are you using?

You can't use Visual Studio MSBuild from a .NET Core app; the core MSBuild implementation is very similar but tasks and targets differ--there's no guarantee that a project that works in VS will even load in Core, much less build.

baruchiro commented 5 years ago

Do you plan to add .net core support?

rainersigwald commented 5 years ago

Support for finding and using MSBuild from a .NET Core SDK in a .NET Core application was added in #51.

We don't plan to have any kind of support for finding and using MSBuild from a Visual Studio instance in a .NET Core application.

baruchiro commented 5 years ago

Too bad. I try every possible way to find a way to work with project files (.*proj).

Alex-Sob commented 1 year ago

@rainersigwald Ok, so VS 2022 still creates a project targeting net472 when I choose "Stand-Alone Code Analysis Tool" template. I would like to switch the project to net6.0, what is the suggestion?