CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    How to move an *.exe to another solution folder on Postbuild?

    I have seen solutions that build a set of applications and upon completion of the build copy all the *exe 's or *lib 's or *.dll 's to a central directory in the solution. I have found the Postbuild syntax to do this VERY confusing and have NEVER been able to accomplish this.

    Can anyone provide the proper syntax to do this? Any help greatly appreciated. Thanks.
    mpliam

  2. #2
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to move an *.exe to another solution folder on Postbuild?

    You know the standard shell commands I suppose? If not open a shell and give the command help.

    If you know them it's just the same syntax as you use if doing it manually but you use macros to find your way to folders and files.

    copy $(OutDir)\$(ProjectName).exe c:\$(ProjectName).exe

    will for instance copy the resulting exe file to the root of drive c.

    When you have opened the post event dialog click on Macros and you will be presented with bunch of macros and their current value.

    Let's say you have a top solution and a number of project residing in sub-folders and you want the output to end up in a sub-folder, result, at the same level as the project folders.

    In the finalizing project (the project that depends on all the other, probably the exe project) you add something like

    mkdir $(SolutionDir)\..\result\debug
    copy $(SolutionDir)\project1\debug\*.dll $(SolutionDir)\..\result\debug\*.*

    and so on. Was this what you asked for or was it something more complex?
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  3. #3
    Join Date
    May 2002
    Posts
    1,798

    Re: How to move an *.exe to another solution folder on Postbuild?

    Thank you for you very clear explanation of how to use Post-Build macros.

    A fundamental question arises: How best to organize a solution that contains several interdependent projects?

    Say one has project P1, P2, P3, and P4. P3 happens to be a dll that P2 and P4 depend upon. In such a situation, I have proceeded as follows:

    1 - Create the 4 new projects (File/New/Project...)
    2 - Make a new (empty) solution folder
    3 - copy (or drag) the 4 projects to the new solution folder using Explorer copy and paste
    4 - Open Visual Studio and open P1
    5 - Highlight Solution (top line) in VS Solution Explorer
    6 - Right click, Use Add Existing Project to add each project (*.vcproj) to the solution
    7 - Right click on one of the projects and Set As Startup Project (machs nicht?)
    8 - Build the solution

    If one proceeds this way (Visual Studio 2008, VC 9.0), all projects will get built and the first project added to the solution (not necessarily the startup project) will have all of the other project *.exe's, *.lib's, and *.dll's in it's Release and/or Debug folders. THIS IS NOT THE CASE FOR ANY OF THE OTHER PROJECTS. This occurs without any editing of Post-Build events.

    I have noticed in downloading solutions from other more sophisticated developers that they have, in addition to a *.sln file for each project, what appears to be a 'master' *.sln file for the entire collection of projects. I have always wondered how they accomplish this and what overall effect it has on the solution build.

    As regards editing Post-Build Events, I have tried without success to use the Shell commands and macros as you have suggested. For example, if I simply try to create a 'Result' directory for the solution and copy one of the project *.exe's using the following syntax in the P1 Post-Build Event editor, the solution builds but I get the subsequent error:

    mkdir $(SolutionDir)\..\Result\Debug
    copy $(SolutionDir)\P1\Debug\P1.exe $(SolutionDir)\..\Result\Debug\P1.exe

    Error 1 error PRJ0019: A tool returned an error code from "Performing Post-Build Event..."

    I simply cannot get the syntax right. Any further thoughts or comments greatly appreciated.
    Last edited by Mike Pliam; August 31st, 2010 at 10:43 AM.
    mpliam

  4. #4
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: How to move an *.exe to another solution folder on Postbuild?

    Try opening the post build editor, check the macro values and copy/paste them into a bat file that do the same thing as the post build step. Since $(SolutionDir) is the full path to where you sln file resides the bat file should work regardless of where it's placed.

    The easiest way to create a "master" sln file is to start by opening the vcproj file for a "sub" project, do save-as "on top" of all projects and then add all other "sub" projects to the top sln. Don't forget to set project dependencies.

    You can safely delete the sln files for the individual projects (the same goes for sou and ncb but first close studio). Just open vcproj again if you for some reason miss them.
    Last edited by S_M_A; August 31st, 2010 at 03:01 PM.
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  5. #5
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: How to move an *.exe to another solution folder on Postbuild?

    If I understand what you're trying to do, I take a different approach. I currently have 38 applications that are supported by 19 DLLs and a few libs along the way.

    My basic file structure is:
    Code:
    \Source
        \bin
        \lib
        \Project1
        \Project2
        \Project3
        \Project4
        \Project5
    I set up each project so that it's output goes in the proper place when it is compiled:

    1. Static library project put their output (the .lib file) into the \Source\lib directory
    2. DLL projects put their output (the .dll file) into the \Source\bin folder and the .exp and .lib files into the \Source\lib folder
    3. EXE projects put their output file into the \Source\bin folder.

    I then setup my lib path to look for libraries in the \Source\lib folder.

    Using this method, all the required .exe and .dll files are automatically in the correct (\Source\bin) folder, and no Post Build steps are required.

    This also prevents having the current .exe in one folder and a (possibly outdated) .exe in a different folder. Additionally when you CLEAN the solution, it clears out the \Source\bin and \Source\lib files.

    Just another approach to what I think your trying to accomplish.

    Hope it helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  6. #6
    Join Date
    May 2002
    Posts
    1,798

    Re: How to move an *.exe to another solution folder on Postbuild?

    Thank you for your most helpful remarks and ideas.

    I am embarassed to relate that I am unable to avoid the
    error PRJ0019: A tool returned an error code from "Performing Post-Build Event...
    no matter how I have fiddled with the syntax.

    Further, I am ashamed to say that I cannot even get a simple bat file to copy A B with proper syntax. There are numerous examples of this on the web, mostly using xcopy rather than copy (presumably to back up entire directories rather than just single files). But if I attempt to run the following *.bat file from the command prompt
    copy C:/Documents and Settings/Michael B Pliam/My Documents/Visual Studio 2008/Projects/C++/DEPLOYMENT/Source/Debug/P1.exe
    C:/Documents and Settings/Michael B Pliam/My Documents/Visual Studio 2008/Projects/C++/DEPLOYMENT/Source/bin/Debug/P1.exe
    the result is:
    C:\Documents and Settings\Michael B Pliam\My Documents\Visual Studio 2008\Projec
    ts\C++\DEPLOYMENT\Source>config.bat

    C:\Documents and Settings\Michael B Pliam\My Documents\Visual Studio 2008\Projec
    ts\C++\DEPLOYMENT\Source>copy C:/Documents and Settings/Michael B Pliam/My Docum
    ents/Visual Studio 2008/Projects/C++/DEPLOYMENT/Source/Debug/P1.exe
    The syntax of the command is incorrect.

    C:\Documents and Settings\Michael B Pliam\My Documents\Visual Studio 2008\Projec
    ts\C++\DEPLOYMENT\Source>C:/Documents and Settings/Michael B Pliam/My Documents/
    Visual Studio 2008/Projects/C++/DEPLOYMENT/Source/bin/Debug/P1.exe
    'C:/Documents' is not recognized as an internal or external command,
    operable program or batch file.
    As my config.bat file resembles most of the examples I have found (except for the lengthy path names), I am at a complete loss as to what is wrong.

    FWIW, there are about 2000 hits when one Googles the phrase:
    error PRJ0019: A tool returned an error code from "Performing Post-Build Event...
    so I am not alone in having this problem, but this knowledge provides me with little comfort.

    BTW, when I used S M A 's suggestion as to how to employ a 'master' *.sln file, I also deleted all of the project *.sln, *.sou, and *.ncb files, as well as any Debug and Release directories hanging around from the original projects. Voila, a solution build results in ALL the project output *.exe's, *.dll, *.libs, etc being copied automatically to a 'master' solution Release and/or Debug directory. Very nice indeed. And no messing with Post-Build macro editing. However, I still would like to facilitate krmed's directory structure, but I am unable to copy the files from the Source/Debug or Source/Release to the bin/Debug, bin/Release, etc, etc directories. I cannot get the bat file syntax right. Also wondering how to get the *.bat file to run automatically when I build the solution.

    Any further thoughts or ideas ?
    Last edited by Mike Pliam; September 1st, 2010 at 12:19 AM.
    mpliam

  7. #7
    Join Date
    Mar 2008
    Location
    Turin / Italy
    Posts
    178

    Re: How to move an *.exe to another solution folder on Postbuild?

    Just put " " in the whole path. It should look like:
    copy "C:\Documents and Settings\......\P1.exe" "C:\Documents and Settings\......\Source\bin\.............\P1.exe"

  8. #8
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: How to move an *.exe to another solution folder on Postbuild?

    If you want to set up your projects as I suggested, what you need to do is to change the project properties for each of your projects to match what you want.

    For an .exe project, open the project properties, then on the General page, change the Output Directory to "..\bin\". Be sure to do this for both Debug and Release builds. This will cause the resulting .exe to go into the \Source\bin directory. The Intermediate Directory should already be $(ConfigurationName) - that's correct.

    I also change the settings for the Debug build to allow both Debug and Release builds to exist in the \Source\bin directory at the same time. To do this, in the project properties for the Debug build, and on the Linker page change the OutputFile to $(Outdir)$(TargetName)d$(TargetExt) - this results (for Project1) in a file Project1d.exe for Debug and Project1.exe for Release.

    For a .dll project, make the same changes as you did for the .exe project. This puts the .dll file(s) in the \Source\bin directory. Additionally, in the properties Linker section, select Advanced and set the Import Library setting to ..\lib\$(TargetName).lib - for Debug it would be ..\lib\$(TargetName)d.lib. This causes the .lib and .exp files to be in the \Source\lib directory.

    For a static library (.lib) project, Set the General page/Output Directory to ..\lib\. On the Librarian/General page, you can set the Output File to $(OutDir)$(TargetName)$(TargetExt), or for Debug $(OutDir)$(TargetName)d$(TargetExt).

    With these settings in your projects, you don't need any Custom Build actions (Post build copying is not needed).

    Hope this helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  9. #9
    Join Date
    May 2002
    Posts
    1,798

    Re: How to move an *.exe to another solution folder on Postbuild?

    SkyNetTo - Thanks. I was missing the quotes.

    krmed - Thanks for all the great help. With your explanation I have been able to accomplish exactly what I wanted to do. Furthermore, I believe that you have helped me to ascend to a higher level of application development. I really cannot thank you enough.

    Oh yes. Is there any way to set the order of compilation of the projects contained within a given solution? Two reasons for this. First, I need to build the DLL files first before I 'Build Solution', otherwise I get the 'can't find it ...' error for those files linking to the lib. Second, I would like to run a batch file to copy only those files needed to run the application (together with some required data files not initially included in the application build) into a TEST directory that will allow me to debug the application close to it's final environment. I presume this batch can be run from a Post-Build Event of the last project compiled.
    Last edited by Mike Pliam; September 1st, 2010 at 04:32 PM.
    mpliam

  10. #10
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: How to move an *.exe to another solution folder on Postbuild?

    You control the build order by right clicking on each project and using the set dependencies choiice. You should see a combo box at the top that shows Project1 with a list of all other projects in the solution. Check the ones that Project1 directly uses, then drop down the combo box and select the next project. Repeat until all dependencies are defined.

    Hope that solves your problem.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  11. #11
    Join Date
    May 2002
    Posts
    1,798

    Re: How to move an *.exe to another solution folder on Postbuild?

    Yes. That solves the problem. What more can I say but thankyou.
    mpliam

  12. #12
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: How to move an *.exe to another solution folder on Postbuild?

    Actually, with the setup I explained, all the files you need to run the application are in the \Source\bin directory, so there should be no need to copy them someplace else - just run the app from \Source\bin.

    If you clean the solution, you'll see that the bin directory is empty, so what I do is store my data files directly in the bin directory - they don't get deleted when I clean the solutions, but they are always there when I run the apps.

    Glad I was able to provide a different solution that worked for you.

    (You can always rate posts that helped.)
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured