By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,083 Members | 1,274 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,083 IT Pros & Developers. It's quick & easy.

An error occurred when programmatically compile another project

P: 2
Hi,

The following error occurred when i programmatically compile another project from my present project.


The Error:

error CS0234:The type or namespace name 'Windows' does not exist in the namespace 'System' <are you missing an assembly reference>

The Source Code:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Diagnostics;
using System.IO;
using System.Globalization;

namespace Compile2
{


class Class2
{
/// <summary>
/// The main entry point for the application.
/// </summary>

public bool CompileExecutable(String sourceName)
{
FileInfo sourceFile = new FileInfo(sourceName);
//CodeDomProvider provider = null;
CSharpCodeProvider provider = new CSharpCodeProvider();
ICodeCompiler compiler = provider.CreateCompiler();
bool compileOk = false;
// provider = new Microsoft.CSharp.CSharpCodeProvider();


if (provider != null)
{

// Format the executable file name.
// Build the output assembly path using the current directory
// and <source>_cs.exe or <source>_vb.exe.

String exeName = String.Format(@"{0}\{1}.exe",
System.Environment.CurrentDirectory,
sourceFile.Name.Replace(".", "_"));


string[] Myref ={ "System.dll","System.Drawing.dll"};//,"System.Windows.Forms.dll","System.Collections.Ge neric.dll","System.ComponentModel.dll","System.Dat a.dll","System.Drawing.dll","System.Text.dll" };
string MyAsm = "MyAsm.dll";

// CompilerParameters cp = new CompilerParameters(Myref, MyAsm);
CompilerParameters cp = new CompilerParameters();

// Generate an executable instead of
// a class library.
cp.GenerateExecutable = true;

// Specify the assembly file name to generate.
cp.OutputAssembly = exeName;

// Save the assembly as a physical file.
cp.GenerateInMemory = false;

// Set whether to treat all warnings as errors.
cp.TreatWarningsAsErrors = false;

// Invoke compilation of the source file.
CompilerResults cr = compiler.CompileAssemblyFromFile(cp, sourceName);

//CompilerResults cr = new CompilerResults();


if (cr.Errors.Count > 0)
{
// Display compilation errors.
Console.WriteLine("Errors building {0} into {1}",
sourceName, cr.PathToAssembly);
foreach (CompilerError ce in cr.Errors)
{
Console.WriteLine(" {0}", ce.ToString());
Console.WriteLine();
}
}
else
{
// Display a successful compilation message.
Console.WriteLine("Source {0} built into {1} successfully.",
sourceName, cr.PathToAssembly);
}

// Return the results of the compilation.
if (cr.Errors.Count > 0)
{
compileOk = false;
}
else
{
compileOk = true;
}
}
return compileOk;
}

}







class Program
{
static void Main(string[] args)
{
Class2 c2 = new Class2();
c2.CompileExecutable("C:\\temp4\\temp4\\Program.cs ");
Console.WriteLine("hai");
Console.Read();
}
}
}


Expecting quick Response.
Thanks,
Ramesh
Oct 3 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.