Visual Studio 2010 - Post-build event - cd "$(ProjectDir)" exits with code 1 when project is loaded from a network drive

StackOverflow https://stackoverflow.com/questions/17459197

Question

I have a solution running in Visual Studio 2010 SP1.

As part of the solution I have a post-build event where the first line is: cd "$(ProjectDir)" ...

The post build event works fine when the project is loaded locally.

I have setup my laptop with the TFS workspace mapped to a network drive. The solution builds and the website runs just fine - except for the features relying on the post-build event. I have removed all of the Post-build event except the change directory line.

This is the error I get when I build: The command "cd "\\[ComputerName]\b$[ProjectPath]\"" exited with code 1.

The solution is residing solely on the network drive, and it build and runs. I can navigate to the directory in an explorer window without any problems (I saved the network credentials).

The only thing I can find through searching is that exit code 1 means that the path is incorrect, but I can copy and paste the path from the error into an explorer window and browse the directory on the network drive.

Any ideas why the change directory command wont work?

Was it helpful?

Solution

CD is a command used by your shell command interpreter (CMD.EXE).
You cannot pass a CD \\server\share command to CMD.EXE.

Instead I suggest to map your share name to a drive letter like (from the command prompt)

NET USE Z: \\server\share /PERSISTENT:YES

Now you could write a batch file that uses your Z: drive and executes the commands required

For example

CD Z:\projectfolder\bin\release
copy *.exe z:\projectfolder\distribution /Y

You could also pass the predefined macros to this batch file as arguments and use them inside the batch file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top