I use a Visual Studio makefile project and have individual build commands in the NMakeBuildCommandLine property of the vcxproj file.
When one of these commands uses output redirection like this:
echo "unwanted output" >nul 2>&1
I get a build error when calling msbuild:
all.vcxproj(53,30): error MSB4025:
The project file could not be loaded. An error occurred while parsing EntityName. Line 53, position 33.
or
Die Projektdatei konnte nicht geladen werden. Beim Analysieren von 'EntityName' ist ein Fehler aufgetreten. Zeile 53, Position 33.
Why?
I found the solution by myself and want to provide it here.
This error can only happen, if you directly edit the
NMakeBuildCommandLinewithin the vcxproj file.You can get the same error with other command properties too.
The reason is, that
>and&are invalid special characters.As stated in the MSBuild help, special characters need to be escaped.
However in this help
>and&are not listed, although they are invalid in XML elements and a vcxproj is xml.The MSBuild help says
which means to replace
with
By try I found out, that the following variants do also work:
Interestingly, only the last 2 variants are afterwards displayed correctly in the project properties > NMake > Build Command Line as
>nul 2>&1.When editing the project properties > NMake > Build Command Line directly, and you enter
>nul 2>&1, VS writes>nul 2>&1to the vcxproj.And since the last variant is more readable than the hexadecimal syntax, I would prefer this too.
I tested with Visual Studio 17.2.5.
There was also a similar answer here, but it does neither mention the character
>(which is used for output redirection but not contained in the MSBuild help) nor does it mention NMakeBuildCommandLine (that's the problem I was coming from).So I decided to make this new question & answer to help others with a similar problem.