我已经面对这个问题好几个小时了。
我正在玩一点代码,但我得到:一个类型或命名空间线程没有找到。
我的编译器代码如下:
using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CodeDom
{
public class Compiler
{
public Compiler(string sourceCode, string savePath)
{
string[] referencedAssemblies = new string[] { "System.dll", "System.Windows.Forms.dll", "System.Threading.Thread.dll" };
Dictionary<string, string> providerOptions = new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } };
string compilerOptions = "/target:winexe /platform:anycpu /optimize+";
using (CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider(providerOptions))
{
CompilerParameters compilerParameters = new CompilerParameters(referencedAssemblies)
{
GenerateExecutable = true,
GenerateInMemory = false,
OutputAssembly = savePath,
CompilerOptions = compilerOptions,
TreatWarningsAsErrors = false,
IncludeDebugInformation = false,
};
CompilerResults compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters,sourceCode); // source.cs
if (compilerResults.Errors.Count > 0)
{
foreach (CompilerError compilerError in compilerResults.Errors)
{
MessageBox.Show(string.Format("{0}nLine: {1} - Column: {2}nFile: {3}", compilerError.ErrorText,
compilerError.Line, compilerError.Column, compilerError.FileName));
}
return;
}
else
{
MessageBox.Show("Compiled!");
}
}
}
}
}
我不理解,我正确地引用dll System.Threading.Thread.dll但它仍然没有找到它。
您可以试试System.Threading.dll
吗?它的名称中应该没有Thread
。