Visual-studio – MSBuild: error MSB4057: The target does not exist in the project

msbuildtargetvisual studio

We are migrating our compilation system to msbuild, and we've found that some projects report the following error:

c:\src\libs\a_lib\A\A.vcxproj : error MSB4057: The target "C" does not exist in the project.

c:\src\libs\a_lib\B\B.vcxproj : error MSB4057: The target "C" does not exist in the project.

c:\src\libs\a_lib\C\C.vcxproj : error MSB4057: The target "C" does not exist in the project.

c:\src\libs\a_lib\D\D.vcxproj : error MSB4057: The target "C" does not exist in the project.

The compilation line is

msbuild "c:\src\libs\a_lib\a_lib.sln" /nologo "/target:C" /t:build "/p:Configuration=Release" "/p:Platform=Win32"

As can be seen, the solution has several projects. The project itself exists in the solution and can be compiled from within the VS IDE. Also, other targets do not fail (following the example: A, B, D).

Our previous compilation line worked correctly on the same project:

devenv "c:\src\libs\a_lib\a_lib.sln" /project "C" /build /nologo "Release|Win32"

Best Answer

The problem comes from the fact that such project is nested inside a solution folder (Tests in this example) in the Solution Explorer. Target name must include the name of such folders (Tests\C), so the correct compilation line is

msbuild "c:\src\libs\a_lib\a_lib.sln" /nologo "/target:Tests\C" /t:build "/p:Configuration=Release" "/p:Platform=Win32"
Related Topic