Background
Wanted to highlight an error one might experience trying to build a Visual Studio Application from the command line.
Error
Error – Image
Error – Text
error MSB4066: The attribute “Version” in element is unrecognized.
Troubleshooting
Googled on the error message and thanks goodness Stack Overflow came to rescue.
The solution is to ensure that one uses a newer version of MSBuild.
In essence locate the ones that come with Visual Studio and not previous versions.
Solution
Outline
- Find Visual Studio’s MSBuild
- Target the found MSBuild in your build script
Tasks
Find Visual Studio’s MSBuild
Where
Script
setlocal set "_option=/R" set "_folder=C:\Program Files (x86)\Microsoft Visual Studio" set "_app=MSBuild.exe" where %_option% "%_folder%" "%_app%" endlocal
Output
Output – Image
Output – Text
>findVSBuild.cmd >setlocal >set "_option=/R" >set "_folder=C:\Program Files (x86)\Microsoft Visual Studio" >set "_app=MSBuild.exe" >where /R "C:\Program Files (x86)\Microsoft Visual Studio" "MSBuild.exe" C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\amd64\MSBuild.exe
Explanation
- Found MSBuild.exe under Visual Studio 2017
- C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
Target MSBuild in Build Script
Script
setlocal set "_folder=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\" set "_file=msbuild.exe" set "_solution=" "%_folder%"\%_file% %_solution% /p:configuration=debug endlocal pause
Credit
Crediting Martin Ullrich.
As always via Via Stack-overflow ( here ).
Looks like you are not building using the MSBuild.exe that is included in VS 2017 (/ build tools) but rather the MSBuild.exe that ships with .NET Framework, which is an old version (and won’t be updated).