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

Cannot use MSBuildWorkspace in .NET Core Console Application #28870

Closed
joeltankam opened this issue Jul 27, 2018 · 8 comments
Closed

Cannot use MSBuildWorkspace in .NET Core Console Application #28870

joeltankam opened this issue Jul 27, 2018 · 8 comments
Labels
Resolution-Duplicate The described behavior is tracked in another issue

Comments

@joeltankam
Copy link

I'm moving a project from .Net Framework 4.6.1 to .Net Core and I have a problem with MSBuildWorkspace

Version Used: 2.7.0

Steps to Reproduce:

  1. Create a new .NET Core Console Application project (VS Professional 2017 Version 15.7.5, .Net Core 2.1.202)
  2. Install nuget-packages for Microsoft.CodeAnalysis
  3. In the main method write code:
    var workspace = MSBuildWorkspace.Create();

Expected Behavior:

MSBuildWorkspace should compile by using Microsoft.CodeAnalysis.MSBuild.

Actual Behavior:

Compilation error : 'MSBuildWorkspace' could not be found (are you missing a using directive or an assembly reference?)
Microsoft.CodeAnalysis.MSBuild is not present under Microsoft.CodeAnalysis package.

@Tornhoof
Copy link

Tornhoof commented Jul 27, 2018

#17974 (comment) might help.
but it's still not .net core. according to #17974 (comment)

@daveaglick
Copy link
Contributor

Yep, not .NET Standard/Core yet (from the thread @Tornhoof linked):

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.

@joeltankam
Copy link
Author

Thanks @Tornhoof @daveaglick
Is there any workaround ?

@daveaglick
Copy link
Contributor

I’ll just leave this here: https://github.com/daveaglick/Buildalyzer/blob/master/README.md#roslyn-workspaces (be warned that version 1.0 with a totally refactored API is right around the corner)

@jmarolf
Copy link
Contributor

jmarolf commented Jul 27, 2018

Is there any workaround ?

Today MSBuildWorkspace depends on the .NETFramework MSBuild. If you need something for .NET Core you can use AdHocWorkspace like @daveaglick has done on https://github.com/daveaglick/Buildalyzer

@sharwell
Copy link
Member

Duplicate of #17974

@sharwell sharwell marked this as a duplicate of #17974 Jul 31, 2018
@sharwell sharwell added the Resolution-Duplicate The described behavior is tracked in another issue label Jul 31, 2018
@sharwell
Copy link
Member

@DustinCampbell Let me know if there's a better tracking issue for the xplat story of the new MSBuildWorkspace 👍

@EamonNerbonne
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate The described behavior is tracked in another issue
Projects
None yet
Development

No branches or pull requests

6 participants