在 .Net Core 中使用 CSharpCodeProvider [英] Using CSharpCodeProvider in .Net Core

查看:65
本文介绍了在 .Net Core 中使用 CSharpCodeProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些 C# 代码,它们从 SOAP WSDL 和 Swagger 文档动态生成源代码,然后使用 CSharpCodeProvider 类的名为 CompileAssemblyFromSource 的方法对其进行编译.使用 .Net 4.8 这工作正常,但在尝试移植到 .Net Core 3.0 时,我现在收到此错误:

I have some C# code that dynamically generates source code from SOAP WSDLs and Swagger documents, and then compiles it using the CSharpCodeProvider class's method called CompileAssemblyFromSource. Using .Net 4.8 this works fine, but in trying to port to .Net Core 3.0, I now get this error:

此平台不支持操作."

.Net Core 是否支持此功能,或者可能很快会添加?这是一个简化的代码摘录:

Is there support for this functionality in .Net Core, or is it likely to be added soon? Here's a simplified code extract:

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
string[] m_References = new string[] { "System.dll", "System.Core.dll", "System.Data.dll", "System.Net.dll", "System.Net.Http.dll", "System.Runtime.Serialization.dll", "System.ServiceModel.dll", "System.Xml.dll" };
CompilerParameters compilerParameters = CreateCompilerParameters(m_References);
m_CompilerResults = codeProvider.CompileAssemblyFromSource(compilerParameters, m_SourceStringArray);
if (!m_CompilerResults.Errors.HasErrors)
{
    /* render UI using compiled code */
}
else
{
    /* log compiler errors */
}

推荐答案

在 .NET Core 中已过时,您可以使用 roslyn (github | nuget | docs) 代替.

It is obsoleted in .NET Core and you can use roslyn (github | nuget | docs) instead.

这篇关于在 .Net Core 中使用 CSharpCodeProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆