dotnet/roslyn

Replacement for Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace?

davkean opened this issue ยท 30 comments

From @MarkMichaelis on January 20, 2017 23:38

In migrating from VS2015 to VS2017, is Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace the intended replacement for Microsoft.DotNet.ProjectModel.Workspaces.ProjectJsonWorkspace? Or is there some other implementation of Microsoft.CodeAnalysis.Workspace that we should be using?

/cc @GrantErickson, @morrisjoe, @breaman, @ascott18

Copied from original issue: dotnet/project-system#1285

From @srivatsn on January 30, 2017 17:28

Yes MSBuildWorkspace should work for these projects. Now I know @mattwar was looking into MSBuildWorkspace being broken due to MSBuild moving elsewhere. Matt, does MSBuildWorkspace work with MSBuild 15 (which is needed for it to understand .NET core projects).

From @mattwar on January 30, 2017 19:0

Msbuild should work in RC3. Though you'll need to upgrade the app's redirects to include the newest msbuild's redirects found in msbuild.exe.config.

From @josephwoodward on February 23, 2017 0:27

Does MSBuildWorkspace support the .NET Standard? IE, can it be used for loading .NET Core projects on Mac and Linux?

From @mattwar on February 23, 2017 0:30

MSBuildWorkspace only supports desktop clr currently.

From @josephwoodward on February 23, 2017 1:21

Ok, thank you for the prompt reply!

From @josephwoodward on February 23, 2017 2:51

@mattwar Do you have any suggestions as where to look or what to do for anyone that wants to load the new MsBuild .csproj proj format on Mac and Linux?

Would love to see .NET Standard support for MSBuildWorkspace so it will be usable on a Mac or Linux.

@josephwoodward

Regarding

@mattwar Do you have any suggestions as where to look or what to do for anyone that wants to load the new MsBuild .csproj proj format on Mac and Linux?

you might find some info in #14206, and more explicitly, by starting from this #14206 (comment). In the end, it turned out that proposal was not really x-plat either though, but could be worth looking up again.

I think the ideal would be to make MSBuildWorkspace just work in 15.3 - I'm going to take a look and see if this is feasible.

I think the ideal would be to make MSBuildWorkspace just work in 15.3

And what about x-plat story? 15.x and x-plat is two separate concerns, yes?

Any update on the x-plat story for loading csproj workspaces?

Any update on the x-plat story for loading csproj workspaces?

Really interested to know this too! Is it still on the road map?

Me too, could anyone please shared an update on this issue?

In addition, I'd like to ask how people have "replaced" the absence of MSBuildWorkspace so far - I've tried https://github.com/daveaglick/Buildalyzer, but I can't use it due to package incompatibilities (downgrade with Microsoft.Win32.Primitives and similar) - see my UPDATE in the next post. Any comments is appreciated.

@ltcmelo Feel free to open an issue in Buildalyzer if the package incompatibilities are something that could be potentially resolved upstream.

@davkean Thanks for the hint. I'll give it a try compiling it locally and, if I don't see a reason for the incompatibility, I'll fill a report.

UPDATE: I got it working with the 15.7.0 preview.

Any progress on this? Seems it didn't make it into 15.7 which makes me a sad panda ๐Ÿ˜ข

If cross-platform is what's holding this back, I'd strongly suggest ignoring non-Windows platforms for now just to get something shipped to plug this glaring absence - since most users of this package are going to be on Windows, the 80/20 rule applies.

See also: #17968

@IanKemp: The new MSBuildWorkspace is in the Roslyn 2.9.0 which are not yet on NuGet.

@DustinCampbell - is 2.9.0 available via a preview feed to give it a try? :-)

Yes. It has been for awhile now. However, if I recall correctly, you're looking for a cross-plat version, correct? Currently, it only supports Windows.

You are correct (I'm looking for xplat). Was quickly scanning the notification and got my hopes up!

For anyone looking for the preview bits including MSBuildWorkspace: add https://dotnet.myget.org/F/roslyn/api/v3/index.json as a package source in VS, then open the Package Manager for your project, ensure "Include prerelease" is ticked and that your "Package source" is set to "All", and then install Microsoft.CodeAnalysis.Workspaces.Common (3.0.0-dev as of the time of this writing).

Note that, because the MSBuild bits are still not available in .NET Standard/Core, your project has to target .NET Framework 4.6 or higher.

Bah, saw this had been updated and got all excited thinking cross-platform support was finally added :(

It's not clear from reading through this issue (forgive me if this is mentioned somewhere and I missed it) -- is .NET Standard support for MSBuildWorkspace something that's planned?

Any updates on this?

Any plans to enable cross-platform support?

Definitely still interested in cross-platform support for this. I'm writing a static analysis and code exploration tool and not having this API on macOS and Linux is pretty unfortunate. Willing to help implement as well.

It is my understanding that this should "just work" now if you use MSBuildLocator with a .NET Core SDK installed

Oh perfect! Thanks for the clarification.

Thanks for the link to the locator, solved my issues too!

In case sometime finds this after some googling, to use MSBuildWorkspace on .net core you can follow these instructions: https://docs.microsoft.com/en-us/visualstudio/msbuild/updating-an-existing-application - essentially adding a reference to Microsoft.Build.Locator; adding ExcludeAssets="runtime" to other Microsoft.Build.??? <PackageReferences>, and calling MSBuildLocator.RegisterDefaults(); at the start of your program.