Build Macros of Visual Studio

If you’re working with lot of projects, or you want to release your DLL to specific location you may need to add some extra actions to to your build.

For example. You have project that uses a DLL of another project of another solution. Sometimes you build your DLL in debug mode, sometimes you build your DLL in release mode. When you build your class library output directory depends on the build mode. Question is: Which DLL will be referenced by your project? To prevent this confusion you can add an copy operation to your post-build events. Then reference the copied DLL.

Here is the sample macro to do this:

cd $(OutDir) 
copy $(TargetFileName) D:\Sources\DLLReferences\MyProjectOutput

Just go to your project properties. Switch “Build Events” tab. Add this sample macro to Post-build event command line. When you build your it will copy result file to specified location.

Figure 1: Build events window of your project.
Figure 2: A Build event Command line window

You can find a list of macros and their descriptions here:

$(ConfigurationName)

The name of the current project configuration, for example, “Debug|Any CPU”.

$(OutDir)

Path to the output file directory, relative to the project directory. This resolves to the value for the Output Directory property. It includes the trailing backslash ‘\’.

$(DevEnvDir)

The installation directory of Visual Studio 2005 (defined with drive and path); includes the trailing backslash ‘\’.

$(PlatformName)

The name of the currently targeted platform. For example, “AnyCPU”.

$(ProjectDir)

The directory of the project (defined with drive and path); includes the trailing backslash ‘\’.

$(ProjectPath)

The absolute path name of the project (defined with drive, path, base name, and file extension).

$(ProjectName)

The base name of the project.

$(ProjectFileName)

The file name of the project (defined with base name and file extension).

$(ProjectExt)

The file extension of the project. It includes the ‘.’ before the file extension.

$(SolutionDir)

The directory of the solution (defined with drive and path); includes the trailing backslash ‘\’.

$(SolutionPath)

The absolute path name of the solution (defined with drive, path, base name, and file extension).

$(SolutionName)

The base name of the solution.

$(SolutionFileName)

The file name of the solution (defined with base name and file extension).

$(SolutionExt)

The file extension of the solution. It includes the ‘.’ before the file extension.

$(TargetDir)

The directory of the primary output file for the build (defined with drive and path). It includes the trailing backslash ‘\’.

$(TargetPath)

The absolute path name of the primary output file for the build (defined with drive, path, base name, and file extension).

$(TargetName)

The base name of the primary output file for the build.

$(TargetFileName)

The file name of the primary output file for the build (defined as base name and file extension).

$(TargetExt)

The file extension of the primary output file for the build. It includes the ‘.’ before the file extension.

Reference: Pre-build Event/Post-build Event Command Line Dialog Box

Örnek:

cd $(OutDir)
copy $(TargetFileName) C:\_References\Fabrikafa\$(ProjectName)
copy *.txt C:\_References\Fabrikafa\$(ProjectName) 
Posts created 141

Leave a Reply

Related Posts

Begin typing your search term above and press enter to search. Press ESC to cancel.

Back To Top