gpt4 book ai didi

c# - CodeDomProvider.CreateCompiler() 已过时

转载 作者:可可西里 更新时间:2023-11-01 08:25:59 27 4
gpt4 key购买 nike

CSharpCodeProvider codeProvider = new CSharpCodeProvider();
ICodeCompiler MyCompiler = codeProvider.CreateCompiler();
CompilerParameters myParameters = new CompilerParameters();
myParameters.GenerateExecutable = true;
myParameters.OutputAssembly = @"prog.exe";
myParameters.TreatWarningsAsErrors = false;
CompilerResults results = myCompiler.CompileAssemblyFromFile(myParameters,"prog.txt");

如何编写这段代码来消除此警告:

System.CodeDom.Compiler.CodeDomProvider.CreateCompiler()' is obsolete: '"Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class. Those inheriting from CodeDomProvider must still implement this interface, and should exclude this warning or also obsolete this method.**

最佳答案

使用this method相反:

CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");

扩展:

if (CodeDomProvider.IsDefinedLanguage(language))
{
CodeDomProvider provider = CodeDomProvider.CreateProvider(language);
// ...
}
else
Console.WriteLine("ERROR");

关于c# - CodeDomProvider.CreateCompiler() 已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406049/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com