locked
Post-Build Event - Task of Copying Program Data to Working Directory Becomes Undone after Build Completes

    Question

  • Hi Everyone,

    In my C++ Metro app project in VS 11 I have created a Post-Build Event under Project->Properties->Build Events->Post-Build Event. I have set "Use In Build" to Yes and the command-line looks like this:

    cd $(SolutionDir)..\..\data
    md  $(SolutionDir)$(Configuration)\AppX\data
    xcopy $(SolutionDir)..\..\data $(SolutionDir)$(Configuration)\AppX\data  /e /y /d /EXCLUDE:$(SolutionDir)data_excludes.txt

    As you can see it is simply copying the necessary data files for the project from a master "\data" directory to the working directory of my project so that I can properly reference the data during run-time.

    It works fine UNLESS I am starting from a clean build where there is no $(Configuration) directory (in my case "Debug" or "Release"). When this is the case the following happens:

    1. The project builds clean and the $(Configuration) directory is created. Good!

    2. The Post-Build Event script runs and my data is copied to $(Configuration)\AppX\data. Good!

    3. The project executes and crashes upon the first file load because somewhere between here and step #2 the \data directory has been removed. 

    Has anyone encountered something similar? Should I put this script somewhere else instead of Post-Build Events?

    My solution for now is:

    4. Touch any source file and build (not clean) which causes my script to run again. This time when I run the build the directory is not deleted.

    Thanks for the help!

    --TheMCP

    Thursday, May 24, 2012 5:56 PM

All replies

  • Hi TheMCP,

    I am moving your thread into the Building Metro style apps with C++  Forum for dedicated support. Thanks for your understanding.

    Best Regards,


    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Friday, May 25, 2012 8:23 AM
  • See if a procmon log doesn't shed some light on it. I am unable to repro implementing this post-build event after creating the needed source files in the ..\..\data folder, and some entries in a data_excludes.txt. If you can't pinpoint it, you could share a sample repro project on SkyDrive for us to investigate.

    Thanks!


    David Lamb



    Friday, May 25, 2012 10:59 PM
    Moderator
  • I'm hitting this too.  The "Run" step of the IDE wipes the AppX directory and any data inside.  So you build, everything is fine, AppX directory is there, AppX/<folder> is in there too.  You run, it's wiped.  You run again, and it's not wiped.  You can watch the post build step repeatedly copy files.  

    I just found out that "Add as Link" is also gone in VS 2012, so I don't appear to be able to add folders as links to my Metro projects.  It's there in VS 2010, and gone in 2012.  

    Tuesday, September 18, 2012 3:09 AM