>Re" /> >Re" /> >Re"/>

How to get the compiler version in a post-build event?

168 Views Asked by At

I would like to add the version of the compiler to an auto-generated release notes file.

Currently, this is what I have:

echo "compiler version:" >>Release_Note.txt
MSBuild.exe -version >>Release_Note.txt

"echo "END." >>Release_Note.txt

When launching this post-build event, it fails with error 9009, most probably because the file MSBuild.exe is not found.

When taking a look at the possible macros, the only "programming environment" related one is DevEnvDir, which equals C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\ on my computer.

A quick search tells me that I have two files MSBuild.exe on my PC, located in these directories:

  • C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin
  • C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64

Both directories are not child folders of the mentioned DevEnvDir macro, so I'm hesitant to use them.

Is there a $Compiler.exe post-build event macro, which I can use for launching the MSBuild.exe -version command?

2

There are 2 best solutions below

0
PMF On

MsBuild --version returns the version of MsBuild, which is (more or less) related to the Visual Studio version. This is not the version of the dotnet (C#) compiler used. To get the .NET version that was used during build use dotnet --version instead (which will in turn report the version that was specified in your global.json, if it exists).

To call dotnet you don't have to search in magical paths, because that is available in the default path.

0
Freeman On

I think you can use the where command in the post-build event to find the location of the MSBuild.exe file and then execute it with the -version argument!

something like this :

echo "compiler version:" >> Release_Note.txt
where /R "C:\Program Files (x86)" MSBuild.exe >> Release_Note.txt
echo "END." >> Release_Note.txt