msbuild: Building a VS solution file at the command line now causes MSB4057

Issue Description

I have a solution file with several projects in and use -targets to selectively build some projects in this solution.

Using

msbuild --version
Microsoft (R) Build Engine version 16.9.0+5e4b48a27 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.9.0.16703

The following works:

msbuild -p:Platform=x64 -p:Configuration=Debug -t:banana SolutionFile.sln

but since installing VS 2019 16.10 Preview 2.1, I now receive error MSB4057: The target "banana" does not exist in the project. for every project in the solution.

I think this update to Visual Studio brought this version of MSBuild with it:

msbuild --version
Microsoft (R) Build Engine version 16.10.0-preview-21181-05+80f316e90 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.10.0.18105

Steps to Reproduce

I have been unable to reproduce this issue in a new project. Unfortunately I cannot share the entire solution with you, nor is it open source.

Expected Behavior

The specified project is targeted and built from the solution.

Actual Behavior

The build does not complete.

Analysis

I emitted the metaproj for build instances, and it looks like there are a few differences, but this one looks related. Looking at SolutionFile.slnmetaproj, I have these two blocks:

16.9

  <Target Name="banana" Outputs="@(bananaBuildOutput)">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)">
      <Output TaskParameter="TargetOutputs" ItemName="bananaBuildOutput" />
    </MSBuild>
  </Target>
  <Target Name="banana:Clean">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Clean" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" />
  </Target>
  <Target Name="banana:Rebuild" Outputs="@(bananaBuildOutput)">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Rebuild" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)">
      <Output TaskParameter="TargetOutputs" ItemName="bananaBuildOutput" />
    </MSBuild>
  </Target>
  <Target Name="banana:Publish">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Publish" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionPath=$(SolutionPath)" />
  </Target>

16.10

  <Target Name="banana">
    <MSBuild BuildInParallel="True" SkipNonexistentProjects="%(ProjectReference.SkipNonexistentProjects)" Projects="@(ProjectReference)" Targets="banana" Properties="BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionFilterName=$(SolutionFilterName); SolutionPath=$(SolutionPath)" />
  </Target>
  <Target Name="banana:Clean">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Clean" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionFilterName=$(SolutionFilterName); SolutionPath=$(SolutionPath)" />
  </Target>
  <Target Name="banana:Rebuild" Outputs="@(bananaBuildOutput)">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Rebuild" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionFilterName=$(SolutionFilterName); SolutionPath=$(SolutionPath)">
      <Output TaskParameter="TargetOutputs" ItemName="bananaBuildOutput" />
    </MSBuild>
  </Target>
  <Target Name="banana:Publish">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="Publish" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionFilterName=$(SolutionFilterName); SolutionPath=$(SolutionPath)" />
  </Target>
  <Target Name="banana:banana">
    <MSBuild Condition="'%(ProjectReference.Identity)' == 'C:\code\banana\msvc\2019\banana.vcxproj'" ToolsVersion="$(ProjectToolsVersion)" BuildInParallel="True" Projects="@(ProjectReference)" Targets="banana" Properties="Configuration=Debug; Platform=x64;BuildingSolutionFile=true; CurrentSolutionConfigurationContents=$(CurrentSolutionConfigurationContents); SolutionDir=$(SolutionDir); SolutionExt=$(SolutionExt); SolutionFileName=$(SolutionFileName); SolutionName=$(SolutionName); SolutionFilterName=$(SolutionFilterName); SolutionPath=$(SolutionPath)" />
  </Target>

After inspecting these generated targets, I can confirm that -t:banana:Clean works in both cases i.e.

msbuild -p:Platform=x64 -p:Configuration=Debug -t:banana:Clean SolutionFile.sln

As does -t:banana:Rebuild.

So I tried -t:banana:banana and this was somewhat of an improvement. It found the correct vcxproj target from the solution but then generated the same error as earlier:

C:\code\banana\msvc\2019\banana.vcxproj : error MSB4057: The target "banana" does not exist in the project.

The main difference between -t:banana and -t:banana:banana is that the former causes MSB4057 for every project in the solution, whereas the latter seems to find the correct project, but then banana does not exist as a target within that project (which makes sense to me).

Versions & Configurations

Working:

msbuild --version
Microsoft (R) Build Engine version 16.9.0+5e4b48a27 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.9.0.16703

Not working:

msbuild --version
Microsoft (R) Build Engine version 16.10.0-preview-21181-05+80f316e90 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

16.10.0.18105

OS is Windows 10, x64, 20H2 (19042.928)

Attach a binlog

Not available.

Thank you!

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 7
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Can’t wait to get a fix. Breaks my entire buildchain scripting.

Is there any chance a regression test for this has/can be implemented? Seems like a very basic functionality that should not be allowed to be broken by a PR?

A workaround from Stack Overflow user chrsdy is to specify the :Rebuild target for the projects explicitly.

msbuild.exe MySolution.sln /t:Project1:Rebuild;Project2:Rebuild;Project3:Rebuild /p:Configuration=Release /p:DebugType=None /p:OutputPath="C:\Users\myuser\Desktop\Build"

VS 16.10.1 is now released.

Indeed! This is my test.

@grantborthwick, the solution for this has been merged and should go into 16.10.1. Let me know if you need it early or if it doesn’t work!

@warappa ah, what’s happening is that VS 16.10 preview 4 delivers a .NET SDK that has an MSBuild that doesn’t have the fix. When the next .NET SDK preview releases with a fixed MSBuild, tye should work fine again.

I can confirm that VS 16.10.1 fixes this issue for my build. Thanks!

Same here - thank you.

I can confirm that VS 16.10.1 fixes this issue for my build. Thanks!

Hi, we are also encountering this issue. We tried solving it by custom build from the vs16.10 branch, which resolved most of the issues, however we probably went wrong somewhere because now when we build the project from Visual Studio first and then trying to build the same project from msbuild (without clean inbetween) we get the following warnings:

warning C4599: '/IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include': command line argument number 3 does not match precompiled header

Would it be possible to do some hotfix release, or just a separate msbuild release that would work with VS 16.10.0? Thanks

Probably 1-3 weeks from now.