Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. CSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails...

CSharpCodeProvider generated EXE embedded with ResourceWriter generated .resources fails...

Scheduled Pinned Locked Moved C#
csharpvisual-studiographicshardwaresecurity
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jon Rista
    wrote on last edited by
    #1

    I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows: PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating compiler...", 3, 1); // Create code compiler CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); // Create compiler parameters PopupProgress.Display("Compiling Installer...", null, "Compiling", "Configuring compiler...", 3, 2); CompilerParameters cparams = new CompilerParameters(); cparams.Evidence = new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence); cparams.GenerateExecutable = true; cparams.GenerateInMemory = false; cparams.IncludeDebugInformation = false; //cparams.MainClass = "S2CIPInstaller.Main"; //cparams.OutputAssembly = step4.CompileTarget; cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true); cparams.ReferencedAssemblies.Add("System.dll"); cparams.ReferencedAssemblies.Add("System.Drawing.dll"); cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll"); // cparams.ReferencedAssemblies.Add("System.XML.dll"); cparams.ReferencedAssemblies.Add(m_basePath + @"temp\SynapticEffect.Collections.dll"); cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll"); cparams.CompilerOptions = "/resource:\"" + m_basePath + "temp\\S2CIPInstaller.resources\""; //cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources"; // Compile PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3); CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code); PopupProgress.Remove(); int errCount = 0; for (int i=0; i 0) { MessageBox.Show(this, "There were errors during compilation. Installer not created."); } else { MessageBox.Show(this, "Installer successfully created!"); }

    J 1 Reply Last reply
    0
    • J Jon Rista

      I have a project where I need to create a windows .exe by compiling code and linking in some resources. This program thats being generated is somewhat unconventional, and I'll explain how. I'm generating a very simple installer app that embeds referenced .dll files inside it, which are extracted and referenced when the installer app is executed. This works great when the installer app is built with Visual Studio .NET, but it does not work when I compile it myself using a CSharpCodeProvider. The resources are written to a .resource file using a ResourceWriter just prior to compilation of the .exe. I add a custom compiler option to embed the resources. Code follows: PopupProgress.Display("Compiling Installer...", null, "Compiling", "Creating compiler...", 3, 1); // Create code compiler CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); // Create compiler parameters PopupProgress.Display("Compiling Installer...", null, "Compiling", "Configuring compiler...", 3, 2); CompilerParameters cparams = new CompilerParameters(); cparams.Evidence = new System.Security.Policy.Evidence(AppDomain.CurrentDomain.Evidence); cparams.GenerateExecutable = true; cparams.GenerateInMemory = false; cparams.IncludeDebugInformation = false; //cparams.MainClass = "S2CIPInstaller.Main"; //cparams.OutputAssembly = step4.CompileTarget; cparams.TempFiles = new TempFileCollection(m_basePath + @"temp\", true); cparams.ReferencedAssemblies.Add("System.dll"); cparams.ReferencedAssemblies.Add("System.Drawing.dll"); cparams.ReferencedAssemblies.Add("System.Windows.Forms.dll"); // cparams.ReferencedAssemblies.Add("System.XML.dll"); cparams.ReferencedAssemblies.Add(m_basePath + @"temp\SynapticEffect.Collections.dll"); cparams.ReferencedAssemblies.Add(m_basePath + @"temp\DatGen.DBPF.dll"); cparams.CompilerOptions = "/resource:\"" + m_basePath + "temp\\S2CIPInstaller.resources\""; //cparams.Win32Resource = m_basePath + @"temp\S2CIPInstaller.resources"; // Compile PopupProgress.Display("Compiling Installer...", null, "Compiling", "Please wait...", 3, 3); CompilerResults results = compiler.CompileAssemblyFromSource(cparams, code); PopupProgress.Remove(); int errCount = 0; for (int i=0; i 0) { MessageBox.Show(this, "There were errors during compilation. Installer not created."); } else { MessageBox.Show(this, "Installer successfully created!"); }

      J Offline
      J Offline
      Jon Rista
      wrote on last edited by
      #2

      I'm kind of desperate at this point. I've done everything I can to get my compiled program to work, but it keeps telling me hte resources are missing, even though hex-editing the .exe shows it there.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups