I am trying to generate an exe with CSharpCodeProvider, exe that will be a windows forms project. The exe has to have a resource which will be accessed at runtime by the generated assembly. Now to generate that resource I am using ResourceWriter class, then appending it to the compiler options, embeddedResources. But it does not seem to work and I get the MissingManifestResourceException.
Here is the code:
FileStream fs = new FileStream("Form1.resources", FileMode.Create);
ResourceWriter writer2 = new ResourceWriter(fs);
writer2.AddResource("bitmap", 3);
writer2.Generate();
writer2.Close();
CSharpCodeProvider code = new CSharpCodeProvider();
CompilerParameters options = new CompilerParameters();
options.GenerateExecutable = true;
options.EmbeddedResources.Add("Form1.resources");
options.OutputAssembly = @"C:\screen.exe";
options.GenerateInMemory = false;
options.TreatWarningsAsErrors = false;
options.ReferencedAssemblies.Add("System.Windows.Forms.dll");
options.ReferencedAssemblies.Add("System.dll");
options.ReferencedAssemblies.Add("System.Drawing.dll");
//options.ReferencedAssemblies.Add("System.Resources.dll");
CompilerResults res = code.CompileAssemblyFromFile(options, "Program.cs", "Form1.cs", "Form1.Designer.cs");
Hope someone is able to help me because I have been trying this for over a week. Thank you.