Open the project properties (Alter+Enter) and then go to "Build Events", select any of the build events, then select "Command Line", click "Edit", then press the "Macros >>" button.
In Visual Studio 2015, you can find ProjectDir by clicking on Macros in additional Include Directories and then clicking on Macros (for me there was nothing in Build Events) :
Same here in Visual Studio 2019, you can find ProjectDir by clicking on Macros in additional Include Directories and then clicking on Macros (for me there was nothing in Build Events), like the answer in above Visual Studio 2015.
Tools -> External Tools
create command for Powershell.exe or Csc.exe
copy exe to c:\ for shorter paths
Name it and check Prompt for arguments
now click Tools -> Click name of your tool
with dialog displayed, click Argument button and choose $(ProjectDir) or whatever.
Your $(ProjectDir) is displayed in Command Line after Powershell.exe or csc.exe
Clear Arguments and click argument button again
Your next selection is display again after command (repeat to view all 16 environment variables.
this is without executing command but command is required to save.
if you use csc.exe from this path
"C:\Program Files\Microsoft Visual Studio\2022\Community\Msbuild\Current\Bin\Roslyn\csc.exe"
copy Roslyn folder to
C:\Roslyn
csc.exe needs other files to work, you need whole directory.
Roslyn folder is only 34 Mb