dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.04k stars 4.03k forks source link

Compatibility between Microsoft.Code.Anaysis and netCore apps #20299

Closed ddydeveloper closed 2 weeks ago

ddydeveloper commented 7 years ago

I tried to use Microsoft.CodeAnalysis Workspaces s in netCore app, unfortunately i had errors.

This is my project github repository reference: https://github.com/ddydeveloper/Roslyn.ApiClient.Codegen/tree/dev/src/Roslyn.Codegen Problem in the file with path:

src/Roslyn.Codegen.WorkspaceParser/ApiClientParser.cs

(Commented code)

Version Used:

  1. netCore 1.1 class library
  2. Microsoft.CodeAnalysis 2.2.0 package

Steps to Reproduce:

  1. Create a netCore 1.1 class library application
  2. Add Microsoft.CodeAnalysis 2.2.0 nuget package
  3. Add using directive into code in netCore app class: using Microsoft.CodeAnalysis.MsBuild;

Expected Behavior: Usign Microsoft.CodeAnalysis.MsBuild directive without any problems

Actual Behavior: Had error: The type or namespace name "MsBuild" does not exists in the namespace Microsoft.CodeAnalysis

For another think I had not blocking error with Microsoft.Composition package (included reference) compatibility. It can be fixed by addind System.Composition package reference but I'm not sure that it is the right way.

Did anybody have such problems?

Pilchie commented 7 years ago

MSBuildWorkspace and related types are .NET Framework only right now, and don't work on .NET Core.

For the 2.2. packages, you can add a <PackageReferenceFallback> for Microsoft.Composition. That issue should be fixed in the recent 2.3 based packages though.

nothrow commented 7 years ago

Isn't this basically duplicate of https://github.com/dotnet/roslyn/issues/16040 ?

Pilchie commented 7 years ago

The second half is, but that is only about System.Composition, not also using MSBuildWorkspace.

ddydeveloper commented 7 years ago

@Pilchie, thanks! I supposed that MSBuildWorkspace does't work on .Net Core right now. I'll try to write same project on Net Framework 4.6.1. Is it planned to implement compatibility with .Net Core?

@nothrow yes, it is duplicate. I closed with issue and will wait 2.3 version!

Pilchie commented 7 years ago

@DustinCampbell can answer better than me (probably next week, as he's on vacation right now). .NET Core is tricky, since MSBuild requires running tasks, so a .NET Core app can't load projects targeting .NET Framework, since the .NET Framework tasks won't run on .NET Core.

ddydeveloper commented 7 years ago

@DustinCampbell, could you help me to understand how to work with MSBuildWorkspace from Microsoft.CodeAnalysis package if I use NET.Core 2.0 project.

I use Microsoft.CodeAnalysis 2.3.2 version and can't find Microsoft.CodeAnalysis.MSBuild workspace: "it does't exists in the current context". This problem was actual early, in 2.0 version on the package, but I expected that it must be fixed in the 2.3.*.

There is reference to the repo with the project: https://github.com/ddydeveloper/Roslyn.ApiClient.Codegen

I'll be grateful for help!

CyrusNajmabadi commented 2 weeks ago

Closing out due to lack of feedback in 7 years.