Build Error with PostBuild script

It seems that regardless of what command I put into the Post-Build property of my project I get the error:

'C:\Documents' is not recognized as an internal or external command, operable program or batch file.

The system cannot find the path specified.

I've tried even simple things like "echo hello." and I get the same result.

echo hello.

'C:\Documents' is not recognized as an internal or external command, operable program or batch file.

The system cannot find the path specified.

As an experiment, I created a C:\Documents.bat file, and sure enough, it gets executed just fine. I also get the same problem whether I use prebuild or postbuild.

Has anyone else encountered this problem And more importantly is there a known fix or workaround

Thanks,

-- Michael --



Answer this question

Build Error with PostBuild script

  • squibbon

    Mike,

    What is the exact (anonimized, ofcourse) path to your PostBuild script

    It may be sound odd, but probably filenames with spaces in it are not supported.
    Try to use a path something like "C:\PostBuildScripts\YourScript.bat".

    This should do the trick!



  • jcrawfo2

    If I simply put "echo hello" (without the quotes) as a pre-build or post-build event command line I get no such error. There must be something else going on there.

    Maybe if you post the entire Build output we can see what's going on.



  • Hasie

    Possibly related - I filed a new bug report for it.
  • Manmeet

    The "space in the pathname" thing was the first thing I thought of too. That's obviously what is happening, but I don't know where it is getting the C:\Documents and Settings executable path from. It's not my post-build entry.

    It doesn't matter what I put in either the post-build or pre-build settings, the result is consistently the same.

    Originally the path I was using is "$(ProjectDir)$(OutDir)\PostBuild.bat"

    I can see in the Output that it was attempting to execute the proper pathname.

    But the result was always the same, so I started playing with different alternatives but none worked.

    I put things like "echo hello." as the command, and on another run I just used "cmd". These all result in the same error. I then created a C:\Documents.bat file and started putting stuff in there, as expected, it would execute anything I put in that script. I started experimenting by doing things like dumping the environment and executing a cd to try and figure out what the path of the original executable was but without success.

    I just realized that I didn't dump the bat file commandline arguments which should contain the rest of the file path. I'll try that when I get home tonight.

    The only thing "different" I can think about my project is that it lives in "P:\My Documents\My Projects" and not anywhere on the C: drive. I've updated all references I can find (though none were looking at anything related to C:\Documents and Settings) but still no change.

    It seems that VS C# Express is actually trying to execute something in "C:\Documents and Settings" instead of the value I provide in the pre/post build parameters.

    -- Michael --


  • Venkat2Day

    Whenever you use the macros in build events always put quotes around them. E.g.: "$(TargetPath)". They usually expand out to a path in Document and Settings and don't have quotes around them by default. Passing that value to many DOS-based applications will result in using the spaces as filename separation delimiters, and thus, a file not found error (usually).

  • Volksie

    I figured it out last night...

    I put the echo %* into my c:\documents.bat file to see what the full commandline attempting to be executed was. The answer came back "C:\Documents and Settings\M".

    This is significant because when I created the user that my wife and I would share (and more to the point the one I was using to compile the app) I called the log in name "M & J". It didn't occur to me that would translate into a directory named "M & J" in the Docs and Settings folder. I don't know what it is in Docs and Settings that VS is trying to execute but that & is splitting the command up. I created a new user "Michael", logged in and retried and all worked perfectly.

    There is probably a security implication here and regardless it's definitely a bug somewhere (Either disallow me from putting an & in my username, or if I'm allowed to put an & in my username then the other functions need to be ready to handle that (I'm thinking just disallow & in the username)).

    I tried to surgically rename all references everywhere from "M & J" to just "MJ" using the new "Michael" account and safe mode and while it "mostly worked" Windows definitely didn't like my surgically renamed "MJ" user. I'll probably just make a new "MJ" user tonight and migrate the old user data. I already have a redirected My Documents so that makes life easier.

    Thanks everyone for the input,

    -- Michael --


  • DaveMartinNassco

  • B_Li

    I did use quotes in my original build event but my quoting and script references aren't the problem. It's something else.

    The reason I came here to post is that "echo hello." does not in anyway reference anything on any drive, yet the "Can't execute c:\Documents" error remains the same.

    Seriously, I did a Post Build event: echo hello.

    And just to be sure I also did a Post Build event: "echo hello."

    Then as an experiment I did a Pre Build event: echo hello.

    and just to be sure I did a Pre Build event: "echo hello."

    Every single one of those results in a "Can't execute C:\Documents" error.

    Thanks,

    -- Michael --


  • Build Error with PostBuild script