Most of the Visual C++ tooling (but not Clang via its cl driver mode aka clang-cl) will heed the environment variable LOG_BUILD_COMMANDLINES being set.
The value for this environment variable should be the name of a log file and optionally the path to it. One way to achieve this would be to copy&paste the following to a Directory.Build.props or Directory.Build.targets or similar:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" InitialTargets="LogBuild">
<PropertyGroup>
<ThisProjectBuildLogFileName Condition="'$(MSBuildProjectName)' == ''">$(MSBuildThisFileDirectory)BuildCommandLines.log</ThisProjectBuildLogFileName>
<ThisProjectBuildLogFileName Condition="'$(MSBuildProjectName)' != ''">$(MSBuildThisFileDirectory)BuildCommandLines-$(MSBuildProjectName).log</ThisProjectBuildLogFileName>
</PropertyGroup>
<Target Name="LogBuild" BeforeTargets="SetUserMacroEnvironmentVariables;SetBuildDefaultEnvironmentVariables">
<Message Text="Setting LOG_BUILD_COMMANDLINES='$(ThisProjectBuildLogFileName)'" />
<SetEnv Name="LOG_BUILD_COMMANDLINES" Value="$(ThisProjectBuildLogFileName)" Prefix="false" />
</Target>
</Project>
Assuming you use the compiler and linker etc. via .vcxproj or .sln (no matter if IDE or command line), this should create a log file named BuildCommandLines.log in the same directory where you place(d) the Directory.Build.props or Directory.Build.targets. If The property MSBuildProjectName is set, the log file name will be one per project and be: BuildCommandLines-$(MSBuildProjectName).log.
Command line options injected via response files and the known and documented environment variables CL, _CL_, LIB, _LIB_, LINK, _LINK_ etc. seem to get logged as well.
However, it should be noted that command line options injected into individual object files #pragma comment(lib, ...) and #pragma comment(linker, ...) or similar mechanisms will not get logged. Thus this also includes command line options “smuggled” into your project via a static library and the object files contained in it.
PS: if you want to persist this, please use a static <Import /> in your projects instead of a mechanism like Directory.Build.{props,targets} which can simply be suppressed from the outside via environment variable/MSBuild property.