Variables that can be used in Pre / Post build event in Visual Studio


Summary

What values ​​can I use for Pre / Post build event in Visual Studio?
The answer is here:

  • Pre-build event-Post-build event command line dialog – Visual Studio (Windows) | Microsoft Docs
  • In this post, using the following repository as sample code:

    Prerequisites

    • Visual Studio 2019

    Steps

    Enter the following code in Post-build event command line: field.
    The field can be found Build Events menu.

    echo SolutionDir: $(SolutionDir)
    echo SolutionExt: $(SolutionExt)
    echo SolutionFileName: $(SolutionFileName)
    echo SolutionName: $(SolutionName)
    echo SolutionPath: $(SolutionPath)
    
    echo ProjectDir: $(ProjectDir)
    echo ProjectExt: $(ProjectExt)
    echo ProjectFileName: $(ProjectFileName)
    echo ProjectName: $(ProjectName)
    echo ProjectPath: $(ProjectPath)
    
    echo Configuration: $(Configuration)
    echo FrameworkVersion: $(FrameworkVersion)
    echo OutDir: $(OutDir)
    echo Platform: $(Platform)
    echo PlatformShortName: $(PlatformShortName)
    
    echo TargetDir: $(TargetDir)
    echo TargetName: $(TargetName)
    echo TargetPath: $(TargetPath)

    The result is here:

    Build started...
    1>------ Build started: Project: Maya CSharp plug-in, Configuration: Debug Any CPU ------
    1>  Maya CSharp plug-in -> C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya CSharp plug-in\bin\Debug\Maya CSharp plug-in.dll
    1>  SolutionDir: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\
    1>  SolutionExt: .sln
    1>  SolutionFileName: Maya plug-in Wizards.sln
    1>  SolutionName: Maya plug-in Wizards
    1>  SolutionPath: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya plug-in Wizards.sln
    1>  ProjectDir: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya CSharp plug-in\
    1>  ProjectExt: .csproj
    1>  ProjectFileName: Maya CSharp plug-in.csproj
    1>  ProjectName: Maya CSharp plug-in
    1>  ProjectPath: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya CSharp plug-in\Maya CSharp plug-in.csproj
    1>  Configuration: Debug
    1>  FrameworkVersion: 
    1>  OutDir: bin\Debug\
    1>  Platform: AnyCPU
    1>  PlatformShortName: 
    1>  TargetDir: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya CSharp plug-in\bin\Debug\
    1>  TargetName: Maya CSharp plug-in
    1>  TargetPath: C:\Users\hiroakit\Downloads\Maya-Net-Wizards-master\Maya-Net-Wizards-master\Maya CSharp plug-in\bin\Debug\Maya CSharp plug-in.dll
    ========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

    At first I misunderstood and used MSBuild variables in the Post-build event command line: fields, so $FrameworkVersion and $PlatformShortName exists in the code and in the results. It can only be used with MS Build.

    References