Hallo Leute!
Ich habe ein kleines Problem damit, eine Art Installationsroutine zu erstellen (also, selber so eine Art Setup-Programm erstellen)...
Das mit dem Code ist gar kein Problem, ich muss es nur irgendwie schaffen, Ressourcen in die neue *.exe zu integrieren ... kann man das irgendwie machen?
Mein aktueller Code bisher (mit einer einfachen Win-Form):
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom.Compiler;
using System.IO;
using Microsoft.CSharp;
using System.Reflection;
namespace CodeCompiler
{
class Program
{
static string[] code =
{
"using System;"+
"using System.Windows.Forms;"+
""+
"namespace Test"+
"{"+
" public partial class Form1 : Form"+
" {"+
" public Form1()"+
" {"+
" InitializeComponent();"+
" }"+
" }"+
" partial class Form1"+
" {"+
" private System.ComponentModel.IContainer components = null;"+
" protected override void Dispose(bool disposing)"+
" {"+
" if (disposing && (components != null))"+
" {"+
" components.Dispose();"+
" }"+
" base.Dispose(disposing);"+
" }"+
" private void InitializeComponent()"+
" {"+
" this.components = new System.ComponentModel.Container();"+
" this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;"+
" this.Text = \"Form1\";"+
" }"+
" }"+
" static class Program"+
" {"+
" [STAThread]"+
" static void Main()"+
" {"+
" Application.EnableVisualStyles();"+
" Application.SetCompatibleTextRenderingDefault(false);"+
" Application.Run(new Form1());"+
" }"+
" }"+
"}"
};
static void Main(string[] args)
{
CompileAndRun(code);
Console.ReadKey();
}
static void CompileAndRun(string[] code)
{
CompilerParameters CompilerParams = new CompilerParameters();
string outputDirectory = Directory.GetCurrentDirectory();
CompilerParams.GenerateInMemory = false;
CompilerParams.OutputAssembly = "C:\\Test.exe";
CompilerParams.TreatWarningsAsErrors = false;
CompilerParams.GenerateExecutable = true;
CompilerParams.CompilerOptions = "/optimize";
string[] references =
{
"System.dll",
"System.Windows.Forms.dll",
};
CompilerParams.ReferencedAssemblies.AddRange(references);
CSharpCodeProvider provider = new CSharpCodeProvider();
CompilerResults compile = provider.CompileAssemblyFromSource(CompilerParams, code);
if (compile.Errors.HasErrors)
{
string text = "Compile error: ";
foreach (CompilerError ce in compile.Errors)
{
text += "rn" + ce.ToString();
}
throw new Exception(text);
}
}
}
}
Ich hoffe, ihr könnt mir helfen ...
Großes danke im vorraus,
Mfg Marc
Microsoft sagt:
[CompilerParameters-Klasse]
Um in die kompilierte Assembly .NET Framework-Ressourcendateien einzufügen, fügen Sie die Namen der Ressourcendateien in der EmbeddedResources-Eigenschaft hinzu. Um in einer anderen Assembly auf die .NET Framework-Ressourcen zu verweisen, fügen Sie die Namen der Ressourcendateien in der LinkedResources-Eigenschaft hinzu. Um in der kompilierten Assembly eine Win32-Ressourcendatei einzufügen, geben Sie den Namen der Win32-Ressourcendatei in der Win32Resource-Eigenschaft an.
Die "CompilerParameters.EmbeddedResources"-Eigenschaft muss festgelegt werden.
Und was muss ich da angeben? Eine Resource oder eine .resource-datei?
Und wie kann ich das dann nutzen?
Mfg Marc