c# - Xamarin.Forms 中的动态 c# 编译器找不到类型或命名空间
问题描述
我有一个 Xamarin.Forms 应用程序可以在按下按钮时动态编译 c# 代码,但我在代码中遇到错误。
这是按下按钮的代码:
{
string text = ((Editor)sender).Text;
var csc = new CSharpCodeProvider(new Dictionary<string, string>() { { "CompilerVersion", "v3.5" } });
var parameters = new CompilerParameters(new[] { "mscorlib.dll", "System.Core.dll" }, "foo.exe", true);
parameters.GenerateExecutable = true;
CompilerResults results = csc.CompileAssemblyFromSource(parameters, text);
results.Errors.Cast<CompilerError>().ToList().ForEach(error => string errors = error.ErrorText;
}
我正在使用:
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
XAML 是这样的:
<Button x:Name="compilebutton" Text="Compile" Clicked="oncompile" />
The type or namespace name 'CompilerParameters' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CompilerResults' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'CompilerError' could not be found (are you missing a using directive or an assembly reference?)
我已经在没有 Xamarin.Forms 的控制台应用程序中对此进行了测试,它运行良好,我不确定问题是什么,任何帮助将不胜感激,谢谢!
解决方案
推荐阅读
- python - MQL5 读取文件同时被另一个程序写入
- reactjs - 如何根据给定的示例将列数组值添加为行数组中的新数组?
- javascript - 如何在最新的 Chrome/Firefox 中使用 javascript 在按钮单击时从 HTML 页面运行 bat 文件?
- excel - Microsoft Excel 数据透视表,每行包含多个可筛选项/值
- node.js - 如何在mongoDB中计算总数?
- azure - 数据集类型 json 时 Set-AzureRmDataFactoryV2Dataset 中的 Azure 数据工厂 V2 错误
- docker - OpenGrok docker 镜像中的索引配置在哪里?
- java - 无法映射列表
- python - 我有两行代码,我试图进入一行
- reactjs - http url 上的图像显示旧图像而不是更新图像