CodeDOM编译器错误,没有主要入口点

时间:2014-09-04 05:13:48

标签: c# codedom

我正在使用代码:

SaveFileDialog sfd = new SaveFileDialog();
        sfd.ShowDialog();
        string source = Properties.Resources.source;
        CodeDomProvider codeProvider = CodeDomProvider.CreateProvider("CSharp");
        string Output = sfd.FileName + ".exe";
        System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
        parameters.GenerateExecutable = true;
        parameters.OutputAssembly = Output;
        parameters.ReferencedAssemblies.Add("System.dll");
        parameters.ReferencedAssemblies.Add("System.Core.dll");
        parameters.CompilerOptions = "/target:winexe";
        parameters.ReferencedAssemblies.Add("mscorlib.dll");
        parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        parameters.ReferencedAssemblies.Add("System.Management.dll");
        parameters.ReferencedAssemblies.Add("System.Drawing.dll");
        parameters.ReferencedAssemblies.Add("System.Runtime.InteropServices.dll");
        parameters.ReferencedAssemblies.Add("System.DirectoryServices.AccountManagement.dll");
        CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, Properties.Resources.source);

        if (results.Errors.Count > 0)
        {
            foreach (CompilerError CompErr in results.Errors)
            {
                MessageBox.Show("Error on line #" + CompErr.Line + " " + CompErr.ErrorText);
            }
        }
        else
        {
            MessageBox.Show("Successfully Compiled.");
        }

编译我的来源,即:

using System; 
    static void Main(string[] args)
    {

    }

我收到错误:

Error on line #0 Program 'c:\Users\Tom\Desktop\s.exe' does not contain a static 'Main' method suitable for an entry point

从谷歌搜索到这里,我无法找到为什么这会引发错误..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
class Program
{
    public static void Main(string[] args)
    {
    }
}
}

这也不起作用,我收到同样的错误。

0 个答案:

没有答案