如果你想在你的工程中使用Post-Build event來協助你完成一些繁瑣的動作, 比如拷貝檔案, 安裝dll到GAC, 或者使用別的命令列工具來做一些自動化的操作, 那麼你就需要瞭解Visual Studio Build Marcos.
在Pre-Build Event Command Line的編輯器中, 點擊下面的Macro按鈕, 可以看到可用的Marco列表以及, 它們對應的值.
下面的連結中有這些Marco的完整列表和說明.
這裡舉出一個例子:
用下面的代碼作為Post-Build的命令:
echo RemoteMachine = $(RemoteMachine)
echo References = $(References)
echo ConfigurationName = $(ConfigurationName)
echo PlatformName = $(PlatformName)
echo Inherit = $(Inherit)
echo NoInherit = $(NoInherit)
echo StopEvaluating = $(StopEvaluating)
echo ParentName = $(ParentName)
echo RootNameSpace = $(RootNameSpace)
echo IntDir = $(IntDir)
echo OutDir = $(OutDir)
echo DevEnvDir = $(DevEnvDir)
echo InputDir = $(InputDir)
echo InputPath = $(InputPath)
echo InputName = $(InputName)
echo InputFileName = $(InputFileName)
echo InputExt = $(InputExt)
echo ProjectDir = $(ProjectDir)
echo ProjectPath = $(ProjectPath)
echo ProjectName = $(ProjectName)
echo ProjectFileName = $(ProjectFileName)
echo ProjectExt = $(ProjectExt)
echo SolutionDir = $(SolutionDir)
echo SolutionPath = $(SolutionPath)
echo SolutionName = $(SolutionName)
echo SolutionFileName = $(SolutionFileName)
echo SolutionExt = $(SolutionExt)
echo TargetDir = $(TargetDir)
echo TargetPath = $(TargetPath)
echo TargetName = $(TargetName)
echo TargetFileName = $(TargetFileName)
echo TargetExt = $(TargetExt)
echo VSInstallDir = $(VSInstallDir)
echo VCInstallDir = $(VCInstallDir)
echo FrameworkDir = $(FrameworkDir)
echo FrameworkVersion = $(FrameworkVersion)
echo FrameworkSDKDir = $(FrameworkSDKDir)
echo WebDeployPath = $(WebDeployPath)
echo WebDeployRoot = $(WebDeployRoot)
echo SafeParentName = $(SafeParentName)
echo SafeInputName = $(SafeInputName)
echo SafeRootNamespace = $(SafeRootNamespace)
echo FxCopDir = $(FxCopDir)
產生的結果如下:
------ Build started: Project: MacroExposition, Configuration: Debug
Any CPU ------
MacroExposition ->
C:\sandbox\MacroExposition\MacroExposition\bin\Debug\MacroExposition.exe
echo RemoteMachine =
echo References =
echo ConfigurationName = Debug
echo PlatformName = AnyCPU
echo Inherit =
echo NoInherit =
echo StopEvaluating =
echo ParentName =
echo RootNameSpace = MacroExposition
echo IntDir =
echo OutDir = bin\Debug\
echo DevEnvDir = C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\
echo InputDir =
echo InputPath =
echo InputName =
echo InputFileName =
echo InputExt =
echo ProjectDir = C:\sandbox\MacroExposition\MacroExposition\
echo ProjectPath =
C:\sandbox\MacroExposition\MacroExposition\MacroExposition.csproj
echo ProjectName = MacroExposition
echo ProjectFileName = MacroExposition.csproj
echo ProjectExt = .csproj
echo SolutionDir = C:\sandbox\MacroExposition\
echo SolutionPath = C:\sandbox\MacroExposition\MacroExposition.sln
echo SolutionName = MacroExposition
echo SolutionFileName = MacroExposition.sln
echo SolutionExt = .sln
echo TargetDir = C:\sandbox\MacroExposition\MacroExposition\bin\Debug\
echo TargetPath =
C:\sandbox\MacroExposition\MacroExposition\bin\Debug\MacroExposition.exe
echo TargetName = MacroExposition
echo TargetFileName = MacroExposition.exe
echo TargetExt = .exe
echo VSInstallDir =
echo VCInstallDir =
echo FrameworkDir = c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
echo FrameworkVersion =
echo FrameworkSDKDir = C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\
echo WebDeployPath =
echo WebDeployRoot =
echo SafeParentName =
echo SafeInputName =
echo SafeRootNamespace =
echo FxCopDir =
摘自:
Visual studio build macros
http://billfellows.blogspot.com/2009/09/visual-studio-build-macros.html
Macros for Build Commands and Properties
http://msdn.microsoft.com/en-us/library/c02as0cs(VS.71).aspx
http://msdn.microsoft.com/en-us/library/c02as0cs.aspx