0

I try to create application responsible for analysing existing dll and generating output code based on this one. I created .netCore console application as entry point and several .netCore class libraries which incapsulating analysis and generating logic.

The first problem was detected whan i tried to add Mircosoft.Codeanalysis package referense:

Error Package Microsoft.Composition 1.0.27 is not compatible with netcoreapp1.1 (.NETCoreApp,Version=v1.1). Package Microsoft.Composition 1.0.27 supports: portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)

This problem was solved by adding in .csproj file settings:

<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+win81+wp8+wpa81</PackageTargetFallback>

It was enough to completing the first part of the application which generate output code, but when i tried to use MsBuildWorkspace.Create() method to get sln, projects and target classes from input dll, I had this error:

Error CS0103 The name 'MSBuildWorkspace' does not exist in the current context Roslyn.Codegen.WorkspaceParser

I suppose it is assotiate with with using Mircosoft.CodeAnalysis packag in .netCore application.

Unfortunately, I did't find any useful samples with .netCore apps and Roslyn to get best practices in this area and I'm not sure Roslyn and netCore have a good compatibility.

This is link to github repo: https://github.com/ddydeveloper/Roslyn.ApiClient.Codegen/tree/dev

So, is it good idea to mix Roslyn code analysis API and netCore applications? Could you give any good samples or advises how to fix problems with Roslyn and netCore compatibility?

paranamix2
  • 337
  • 2
  • 17
  • I think that portable .net 4.5 has a limited number of classes. You need to target your application to `.NETStandard 1.3` - after this it will be compatible with [`Microsoft.CodeAnalysis.Workspaces.Common 2.2.0`](https://www.nuget.org/packages/Microsoft.CodeAnalysis.Workspaces.Common/). After that you need to remove your `PackageTargetFallback` attribute – VMAtm Jun 13 '17 at 14:50
  • Tried to create .netStandart 1.3 class library and to add Microsoft.CodeAnalysis package reference. Had same issue: Error: Package restore failed. Rolling back package changes for 'Test'. – paranamix2 Jun 13 '17 at 20:46
  • Did you try to restore packages with `dotnet restore`? – VMAtm Jun 13 '17 at 20:52
  • Maybe the best way to use Microsoft.CodeAnalysis.MSBuild in .netFramework 4.6.1 (it works), but it would be great Roslyn provide useful API for .netCore apps – paranamix2 Jun 13 '17 at 20:53
  • Unfortunately, I can't add reference Microsoft.CodeAnalysis becouse of "One or more packages are incompatible with .NETStandard,Version=v1.3" error. – paranamix2 Jun 13 '17 at 21:02
  • I suppose what problems in close with incompatible Microsoft.Composition 1.0.27 and netCore/netStandart apps – paranamix2 Jun 13 '17 at 21:09
  • Yeah, looks like it still not working. You may try to report an issue and get official answers on [GitHub](https://github.com/dotnet/roslyn/issues) – VMAtm Jun 13 '17 at 21:18
  • Thanks, i will report an issue on github! – paranamix2 Jun 13 '17 at 21:25

0 Answers0