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. creating a single EXE from multiple projects

creating a single EXE from multiple projects

Scheduled Pinned Locked Moved C#
debuggingcsharphelpquestion
8 Posts 3 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.
  • M Offline
    M Offline
    mikechambers
    wrote on last edited by
    #1

    Ok. After about 12 hours of trying to combine multiple assemblies into a single EXE, I am finally making some progress. I ended up compiling each class into its own module (quite a pain). I am now trying to use al.exe to combine all of them. If I use the following command line: al.exe ActionNotSpecifiedException.netmodule Arguments.netmodule ConsoleLogger.netmodule DirectoryUtils.netmodule FileLogger.netmodule FileUtils.netmodule ProgCommand.netmodule ProgInfo.netmodule ProgNotFoundException.netmodule InvalidCommandLineException.netmodule Logger.netmodule LoggerArrayList.netmodule LoggerManager.netmodule StreamWriterLogger.netmodule StringArrayList.netmodule TextWriterLogger.netmodule TimeOutException.netmodule ProgCommandRunner.netmodule /main:mesh.Prog.ProgCommandRunner.Main /out:ProgCommand.exe /target:exe I can actually create the ProgCommand.exe executable. Except that it has to be in the same directory as the modules in order to run. So close, yet so far. I also tried to combine everything in my make file with the following code: $(DEST)\$(ASSEMBLY): $(METADATA) $(MODULES) $(DEST) $(CSC) $(EXETARGET) /addmodule:$(MODULES: =;) /main:mesh.Prog.ProgCommandRunner.Main /out:$@ %s which on the command line translates to: csc /nologo /debug+ /d:DEBUG /d:TRACE /t:exe /addmodule:.\Arguments.netmodule;.\InvalidCommandLineException.netmodule;.\DirectoryUtils.netmodule;.\FileU tils.netmodule;.\TimeOutException.netmodule;.\StringArrayList.netmodule;.\Logger.netmodule;.\LoggerArrayList.netmodule;.\TextWriterLogger.netmodule;.\ConsoleLog ger.netmodule;.\StreamWriterLogger.netmodule;.\FileLogger.netmodule;.\LoggerManager.netmodule;.\ActionNotSpecifiedException.netmodule;.\ProgCommand.netmodule;. \ProgNotFoundException.netmodule;.\ProgInfo.netmodule;.\ProgCommandRunner.netmodule /main:mesh.Prog.ProgCommandRunner.Main /out:.\ProgComma nd.exe ..\build\AssemblyInfo.cs However, this gives me the following error: error CS1555: Could not find 'mesh.Prog.ProgCommandRunner.Main' specified for Main method NMAKE : fatal error U1077: 'csc' : return code '0x1' Does anyone have any idea what I am doing wrong? I have been trying to get this to work for quite some time. All I want to do is combine multilple projects into one executable. Thanks in advance... (I hope)... mike c

    L 1 Reply Last reply
    0
    • M mikechambers

      Ok. After about 12 hours of trying to combine multiple assemblies into a single EXE, I am finally making some progress. I ended up compiling each class into its own module (quite a pain). I am now trying to use al.exe to combine all of them. If I use the following command line: al.exe ActionNotSpecifiedException.netmodule Arguments.netmodule ConsoleLogger.netmodule DirectoryUtils.netmodule FileLogger.netmodule FileUtils.netmodule ProgCommand.netmodule ProgInfo.netmodule ProgNotFoundException.netmodule InvalidCommandLineException.netmodule Logger.netmodule LoggerArrayList.netmodule LoggerManager.netmodule StreamWriterLogger.netmodule StringArrayList.netmodule TextWriterLogger.netmodule TimeOutException.netmodule ProgCommandRunner.netmodule /main:mesh.Prog.ProgCommandRunner.Main /out:ProgCommand.exe /target:exe I can actually create the ProgCommand.exe executable. Except that it has to be in the same directory as the modules in order to run. So close, yet so far. I also tried to combine everything in my make file with the following code: $(DEST)\$(ASSEMBLY): $(METADATA) $(MODULES) $(DEST) $(CSC) $(EXETARGET) /addmodule:$(MODULES: =;) /main:mesh.Prog.ProgCommandRunner.Main /out:$@ %s which on the command line translates to: csc /nologo /debug+ /d:DEBUG /d:TRACE /t:exe /addmodule:.\Arguments.netmodule;.\InvalidCommandLineException.netmodule;.\DirectoryUtils.netmodule;.\FileU tils.netmodule;.\TimeOutException.netmodule;.\StringArrayList.netmodule;.\Logger.netmodule;.\LoggerArrayList.netmodule;.\TextWriterLogger.netmodule;.\ConsoleLog ger.netmodule;.\StreamWriterLogger.netmodule;.\FileLogger.netmodule;.\LoggerManager.netmodule;.\ActionNotSpecifiedException.netmodule;.\ProgCommand.netmodule;. \ProgNotFoundException.netmodule;.\ProgInfo.netmodule;.\ProgCommandRunner.netmodule /main:mesh.Prog.ProgCommandRunner.Main /out:.\ProgComma nd.exe ..\build\AssemblyInfo.cs However, this gives me the following error: error CS1555: Could not find 'mesh.Prog.ProgCommandRunner.Main' specified for Main method NMAKE : fatal error U1077: 'csc' : return code '0x1' Does anyone have any idea what I am doing wrong? I have been trying to get this to work for quite some time. All I want to do is combine multilple projects into one executable. Thanks in advance... (I hope)... mike c

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      You cannot use a .NET module from the assembly it is contained in. Why not make one big assembly in the first place? Else you will have to go a long and painful route via IL.

      leppie::AllocCPArticle(Generic DFA State Machine for .NET);

      M 1 Reply Last reply
      0
      • L leppie

        You cannot use a .NET module from the assembly it is contained in. Why not make one big assembly in the first place? Else you will have to go a long and painful route via IL.

        leppie::AllocCPArticle(Generic DFA State Machine for .NET);

        M Offline
        M Offline
        mikechambers
        wrote on last edited by
        #3

        >Why not make one big assembly in the first place? Because my code is broken up into different projects to make it more reusable. I guess i could make one project that linked to all of the other individual files, but I just figured there would be another way to do it. I have been rpetty surprised by how difficult this has been, and how little information i can find on it. Thanks for the info... mike c

        L R 2 Replies Last reply
        0
        • M mikechambers

          >Why not make one big assembly in the first place? Because my code is broken up into different projects to make it more reusable. I guess i could make one project that linked to all of the other individual files, but I just figured there would be another way to do it. I have been rpetty surprised by how difficult this has been, and how little information i can find on it. Thanks for the info... mike c

          L Offline
          L Offline
          leppie
          wrote on last edited by
          #4

          There is an option if you want to make one big exe (unmanaged code will not work here) is to use IL Linker/Binder. Do a search on GotDotNet for it. :)

          leppie::AllocCPArticle(Generic DFA State Machine for .NET);

          1 Reply Last reply
          0
          • M mikechambers

            >Why not make one big assembly in the first place? Because my code is broken up into different projects to make it more reusable. I guess i could make one project that linked to all of the other individual files, but I just figured there would be another way to do it. I have been rpetty surprised by how difficult this has been, and how little information i can find on it. Thanks for the info... mike c

            R Offline
            R Offline
            Rocky Moore
            wrote on last edited by
            #5

            mikechambers wrote: Because my code is broken up into different projects to make it more reusable. Why not take your reusable code and put into into DLLs? That way you just add a reference to your DLLs and they are pulled into your application. This allows you to keep the in different projects and still be used in any of your applications. Just change the type of your project from EXE to DLL for each of those extra projects and add reference in your main application. Rocky Moore <><

            M 1 Reply Last reply
            0
            • R Rocky Moore

              mikechambers wrote: Because my code is broken up into different projects to make it more reusable. Why not take your reusable code and put into into DLLs? That way you just add a reference to your DLLs and they are pulled into your application. This allows you to keep the in different projects and still be used in any of your applications. Just change the type of your project from EXE to DLL for each of those extra projects and add reference in your main application. Rocky Moore <><

              M Offline
              M Offline
              mikechambers
              wrote on last edited by
              #6

              I have been thinking about this. So i could just combine all of the DLLs into one DLL? i.e. I would have one exe and one dll? The DLL would then load the EXE. Would I have to change anything in the EXE or would it know to look in the new DLL? thanks for the input. I am new to c# and thus am not familiar with how apps are usually deployed. mike c

              R 1 Reply Last reply
              0
              • M mikechambers

                I have been thinking about this. So i could just combine all of the DLLs into one DLL? i.e. I would have one exe and one dll? The DLL would then load the EXE. Would I have to change anything in the EXE or would it know to look in the new DLL? thanks for the input. I am new to c# and thus am not familiar with how apps are usually deployed. mike c

                R Offline
                R Offline
                Rocky Moore
                wrote on last edited by
                #7

                Well, actually, you have your program broke up in project right now. You would select the output to be a DLL for each of the projects which contains "supporting code". The project that has your main entry would be set as EXE output. Assuming you have all your projects in one solution file, you would right click on the References item in your project that contains the EXE and select Add Reference. This will bring up a that should have three tabs and the last one being "Projects". The tab will list all the projects that are in the currently solution and you simply select the projects that you main application will need (probably all of them) and hit [Select] and then OK. That will bind those DLLS to your main application. Each project will produce on DLL and you will have your single main application (EXE). When you launch your EXE it will automatically load the DLLS as needed. Not one line of code to do it. You might try just creating a new solution with a single WinForm Windows application. Then Insert another project into the solutions but this time use the "Class Library" project. That will build your skeleton project already set as a DLL. Then in the class it generates simple put a single method in there ( that does: public static IAmHere(string message) { System.Diagnostics.Debug.WriteLine(message); } Right click on you main WinForm project on references and selec the Add References and add the project reference to the Class Library project you created. After that, add in your main form, like in the constructor, a call to your library class you created and the IAMHere function your added to it like: TheClassICreated.IAmHere("Yep"); This will call the method that is in the class library dll you created. To your application it does not care if it is in a DLL or the main application, it calls the same in either case. The only thing you need to do to let your application use the code as if it is in the main application is to add the reference to the project. In the old C++ days, I did not bother with DLLS unless I had to. In C# they are so easy to use, I end up with a dozen or more of them in a sizable application. I build librarys of utility classes, wrappers to controls, abstraction classes for abstracting data, simply popup forms for quick data input, and tons of other things. I put each into a root namespace and then create others similar to the .NET namespaces (like MyLibs.Windows.WinForms for my control wrappers or MyLibs.IO.Data for my data abstraction routin

                M 1 Reply Last reply
                0
                • R Rocky Moore

                  Well, actually, you have your program broke up in project right now. You would select the output to be a DLL for each of the projects which contains "supporting code". The project that has your main entry would be set as EXE output. Assuming you have all your projects in one solution file, you would right click on the References item in your project that contains the EXE and select Add Reference. This will bring up a that should have three tabs and the last one being "Projects". The tab will list all the projects that are in the currently solution and you simply select the projects that you main application will need (probably all of them) and hit [Select] and then OK. That will bind those DLLS to your main application. Each project will produce on DLL and you will have your single main application (EXE). When you launch your EXE it will automatically load the DLLS as needed. Not one line of code to do it. You might try just creating a new solution with a single WinForm Windows application. Then Insert another project into the solutions but this time use the "Class Library" project. That will build your skeleton project already set as a DLL. Then in the class it generates simple put a single method in there ( that does: public static IAmHere(string message) { System.Diagnostics.Debug.WriteLine(message); } Right click on you main WinForm project on references and selec the Add References and add the project reference to the Class Library project you created. After that, add in your main form, like in the constructor, a call to your library class you created and the IAMHere function your added to it like: TheClassICreated.IAmHere("Yep"); This will call the method that is in the class library dll you created. To your application it does not care if it is in a DLL or the main application, it calls the same in either case. The only thing you need to do to let your application use the code as if it is in the main application is to add the reference to the project. In the old C++ days, I did not bother with DLLS unless I had to. In C# they are so easy to use, I end up with a dozen or more of them in a sizable application. I build librarys of utility classes, wrappers to controls, abstraction classes for abstracting data, simply popup forms for quick data input, and tons of other things. I put each into a root namespace and then create others similar to the .NET namespaces (like MyLibs.Windows.WinForms for my control wrappers or MyLibs.IO.Data for my data abstraction routin

                  M Offline
                  M Offline
                  mikechambers
                  wrote on last edited by
                  #8

                  Thanks for the info. This is actually exactly how I have my solution set up, and as you point out, it creates multiple dlls and and EXE. I was trying to find a way to then include all of those in one file, so I don't have to distribute all of the DLLs seperately. thanks again for the suggestions... mike c

                  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