Friday, July 25, 2008

Build events and relative paths

When working with post/pre build events note the following.


1- The build event default path will be the project output path. Everything you write in the build event will be relative to the project output path. So for example. If your application is located at c:\project and it is configured to output things to bin\debug, then your project absolute output path is c:\project\bin\debug. If your output path is different, let’s say it is “..\bin\debug” then your project absolute output path is c:\bin\debug and everything you work on in the build events will start from c:\bin\debug.
The screen below shows how to set the project output path.















Now, when writing a build event paths in a build event, the relative path you use will be relative to that absolute output path which is c:\bin\debug. Ex A post build event like the following will copy the app.config file from c:\config to the output path

Xcopy ..\..\config\app.config *.* /c /y /q


basically the above statement is saying two levels up starting from the absolute project output path which is c:\bin\Debug , that will be C:\ and then it says go to Config folder and get the app.config.


Easy?


now assume you want to to copy a dll

From

C:\TFS1\ASC\ASC.CustomValidations\bin\Debug

To 
C:\TFS1\ASC.PM\ASC.PM.AccountServiceLibrary\bin\Debug 
and your project absolute path is C:\tfs1\ASC.PM\ASC.PM.AccountServiceLibrary\Bin\Debug


Here is what you need to type into the post build event 
xcopy ..\..\..\..\ASC\ASC.CustomValidations\bin\Debug\ASC.CalendarServiceAgent.dll.config


this is 4 levels up starting from the project absolute output path

that's 4 levels up from

C:\tfs1\ASC.PM\ASC.PM.AccountServiceLibrary\Bin\Debug

and that would be

C:\tfs1\


now go to ASC\ASC.CustomValidations\bin\Debug\ASC.CalendarServiceAgent.dll.config starting from c:\tfs1


and that would be 
C:\TFS1\ASC\ASC.CustomValidations\bin\Debug


and your target folder is the same as your absolute output path so you really do not need to type any path as a target path, so you just type *.*