Cannot compile simple dynamic code after migration on .netstandard 2.0 (CodeDom throws System.PlatformNotSupportedException)

前端 未结 2 723
Happy的楠姐
Happy的楠姐 2021-02-09 01:38

Trying to compile this sample of code:

var c = new CSharpCodeProvider();
var cp = new CompilerParameters();
var className = $\"CodeEvaler_{Guid.NewGuid().ToStrin         


        
2条回答
  •  天涯浪人
    2021-02-09 01:54

    I had the same problem with .NetCore 2, but with a bigger CodeDOM project. My solution I am right now building is generating the source from CodeDom and then passing it to Roslyn. (As Roslyn was mentioned in a comment, but only a .NET Framwork solution was posted)

    Here is a good example how to use Roslyn - just add the

    Microsoft.CodeAnalysis.CSharp NuGet package and System.Runtime.Loader NuGet package

    and then use the code here (Or just follow the example): https://github.com/joelmartinez/dotnet-core-roslyn-sample/blob/master/Program.cs

提交回复
热议问题