MSBuild – Error – ‘error MSB4066: The attribute “Version” in element is unrecognized.’

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

Google

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

  1. Find Visual Studio’s MSBuild
  2. 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
  1. 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).

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s