我想建立我的應用程序生成器,這是建設者的CodeDOM沒有編制
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.CodeDom.Compiler;
using Microsoft.CSharp;
namespace MyAppBuilder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BuildBtn_Click(object sender, EventArgs e)
{
CompilerParameters Params = new CompilerParameters();
Params.GenerateExecutable = true;
Params.ReferencedAssemblies.Add("System.dll");
Params.ReferencedAssemblies.Add("System.Drawing.dll");
Params.ReferencedAssemblies.Add("System.Windows.Forms.dll");
Params.ReferencedAssemblies.Add("System.Runtime.InteropServices.dll");
// Params.ReferencedAssemblies.Add("System.Diagnostics");
Params.ReferencedAssemblies.Add("System.Threading.dll");
Params.ReferencedAssemblies.Add("System.IO.dll");
//Params.ReferencedAssemblies.Add("Microsoft.Win32.dll");
Params.OutputAssembly = "output.exe";
Params.CompilerOptions = " /target:winexe";
string Source = Properties.Resources.LockerSource;
CompilerResults results = new CSharpCodeProvider().CompileAssemblyFromSource(Params, Source);
if (results.Errors.Count < 0)
{
MessageBox.Show("nice");
}
else
{
foreach (var error in results.Errors)
{
MessageBox.Show(error.ToString());
}
}
}
}
}
的來源,這是我想建立 不注重referrence組件的應用程序的源加入CsharpCodeProvider
using System;
using System.Drawing;
using System.Windows.Forms;
namespace MyApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
#region AddControls
//Basic Form Seetings
this.Text = "AppName";
this.ControlBox = false;
this.ShowInTaskbar = false;
//Add Contidions TextBox
RichTextBox conditions = new RichTextBox();
this.Controls.Add(conditions);
conditions.Width = this.Width;
conditions.Height = this.Height/2;
conditions.BackColor = this.BackColor;
conditions.BorderStyle = BorderStyle.None;
conditions.Text [email protected]"Sometext";
conditions.Font = new Font(conditions.Font.FontFamily, 8, conditions.Font.Style | FontStyle.Bold);
conditions.Location = new Point(0, 130);
conditions.Enabled = false;
this.Width += 15;
//Add Contidions TextBox
//Add CodeTextBox
TextBox codeBox = new TextBox();
this.Controls.Add(codeBox);
codeBox.Width = this.Width - 60;
codeBox.Location = new Point(20, 10);
codeBox.TextAlign = HorizontalAlignment.Center;
//Add CodeTextBox
//Add DownloadButton
Button DownloadBtn = new Button();
this.Controls.Add(DownloadBtn);
DownloadBtn.Location = new Point(19, 35);
DownloadBtn.Width = 130;
DownloadBtn.Height = 30;
DownloadBtn.Text = "Download Code";
Button SubmitBtn = new Button();
this.Controls.Add(SubmitBtn);
SubmitBtn.Location = new Point(this.Width - 169, 35);
SubmitBtn.Width = 130;
SubmitBtn.Height = 30;
SubmitBtn.Text = "Submit";
Button VerifyEmailBtn = new Button();
this.Controls.Add(VerifyEmailBtn);
VerifyEmailBtn.Location = new Point(19, 70);
VerifyEmailBtn.Width = codeBox.Width + 1;
VerifyEmailBtn.Height = 30;
VerifyEmailBtn.Text = "Click here if you need to verify your email";
//Add DownloadButton
#endregion
}
}
}
,但我得到以下錯誤
the type or namespace name "Form" could not be found(are you missing a using directive or an assembly reference)
我明白錯誤就是不明白我可能會錯過什麼。
我希望我得到一些迴應,因爲我真的卡住了。
你編譯沒有出現具有的InitializeComponent()的代碼;你可能會試着把它拉出來。 – Pete
如果我刪除initializeComponent()我得到了一大堆其他錯誤 –
那麼我需要添加什麼其他代碼,是啊可能是一個菜鳥錯誤,請指出:) –