Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining Build target in before.Solution.sln.targets causes hang, MSB0001 #5071

Closed
Joe-houghton opened this issue Jan 24, 2020 · 7 comments · Fixed by #5109
Closed

Defining Build target in before.Solution.sln.targets causes hang, MSB0001 #5071

Joe-houghton opened this issue Jan 24, 2020 · 7 comments · Fixed by #5109
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug regression triaged

Comments

@Joe-houghton
Copy link

Joe-houghton commented Jan 24, 2020

Hi,
Sorry this is going to be vague, but I wanted to log it with you anyway.
Msbuild is hanging when I invoke directly on our solution. Works fine in 16.3.X, but hangs/fails on 16.4.X.
When pushing Ctrl+c to cancel the build I get the error at the bottom of the post.

Steps to reproduce

Unfortunately I cannot attach a sample as it is of our proprietary software.
Our solution is about 70 projects, with a mix of C#, C++ and C++/CLR.
I have included the import config from Visual Studio.
2019.vsconfig.txt

Environment data

Invoking MSBuild Directly:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin>msbuild "C:\pathto\OurSolution.sln"
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
Build started 24/01/2020 11:51:10.
Attempting to cancel the build...

Build FAILED.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:45.57 (edit: this is an example, I have waited hours and nothing appears on the commandline)
MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Object[] args)
   at Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(Boolean condition, String unformattedMessage, Object arg0)
   at Microsoft.Build.Execution.ProjectInstance.AddTarget(String targetName, String condition, String inputs, String outputs, String returns, String keepDuplicateOutputs, String dependsOnTargets, String beforeTargets, String afterTargets, Boolean parentProjectSupportsReturnsAttribute)
   at Microsoft.Build.Construction.SolutionProjectGenerator.AddTraversalReferencesTarget(ProjectInstance traversalProject, String targetName, String outputItem)
   at Microsoft.Build.Construction.SolutionProjectGenerator.AddStandardTraversalTargets(ProjectInstance traversalInstance, List`1 projectsInOrder)
   at Microsoft.Build.Construction.SolutionProjectGenerator.CreateTraversalInstance(String wrapperProjectToolsVersion, Boolean explicitToolsVersionSpecified, List`1 projectsInOrder)
   at Microsoft.Build.Construction.SolutionProjectGenerator.CreateSolutionProject(String wrapperProjectToolsVersion, Boolean explicitToolsVersionSpecified)
   at Microsoft.Build.Construction.SolutionProjectGenerator.Generate()
   at Microsoft.Build.Execution.ProjectInstance.GenerateSolutionWrapper(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, BuildEventContext projectBuildEventContext, IReadOnlyCollection`1 targetNames, ISdkResolverService sdkResolverService, Int32 submissionId)
   at Microsoft.Build.Execution.ProjectInstance.LoadSolutionForBuild(String projectFile, PropertyDictionary`1 globalPropertiesInstances, String toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext, Boolean isExplicitlyLoaded, IReadOnlyCollection`1 targetNames, ISdkResolverService sdkResolverService, Int32 submissionId)
   at Microsoft.Build.Execution.BuildManager.LoadSolutionIntoConfiguration(BuildRequestConfiguration config, BuildRequest request)
   at Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node, BuildRequestBlocker blocker)
   at Microsoft.Build.Execution.BuildManager.IssueBuildSubmissionToScheduler(BuildSubmission submission, Boolean allowMainThreadBuild)
   at Microsoft.Build.Execution.BuildManager.<>c__DisplayClass70_0.<ExecuteSubmission>b__0()
   at Microsoft.Build.Execution.BuildManager.ProcessWorkQueue(Action action)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Build.Execution.BuildManager.EndBuild()
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)

Unhandled Exception: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main()
@danmoseley
Copy link
Member

Hello, does it reproduce if you just have the solution file, no source files or projects? If so that would make it easy to reproduce here.

Is it possible to share just the solution file- you can obfuscate the project names inside if you need to.

@Joe-houghton
Copy link
Author

Hi Dan,
Thanks for the reply. I will see what I can do on Monday when I am back in the office.
Thanks
Joe

@danmoseley
Copy link
Member

The solution file may be corrupted actually. Save a backup, then make a change in VS (eg add and remove a project) to force VS to write it out again. See whether that helps?

@Joe-houghton
Copy link
Author

Hi Dan,

I have been through and worked out that it is the targets file that is causing the freeze/hang.
Deleting this file and then running msbuild then works in 16.4.X
We use this to keep all the versions in sync.

before.OutSolution.sln.targets

@danmoseley
Copy link
Member

Thanks, that's the repro then.

  1. Create some project, eg ConsoleApplication1.csproj and ConsoleApplication1.sln
  2. Next to the .sln create a targets file named like before.Consoleapplication1.sln.targets with this content
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
  </Target>
</Project>
  1. Run msbuild.exe on the sln

--> it hangs. Hit Ctrl-C and you get

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Object[] args)
   at Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(Boolean condition, String unformattedMessage, Object arg0)
   at Microsoft.Build.Execution.ProjectInstance.AddTarget(String targetName, String condition, String inputs, String outputs, String returns, String keepDuplicateOutputs, String dependsOnTargets, String beforeTargets, String afterTargets, Boolean parentProjectSupportsReturnsAttribute)
   at Microsoft.Build.Construction.SolutionProjectGenerator.AddTraversalReferencesTarget(ProjectInstance traversalProject, String targetName, String outputItem)
   at Microsoft.Build.Construction.SolutionProjectGenerator.AddStandardTraversalTargets(ProjectInstance traversalInstance, List`1 projectsInOrder)
   at Microsoft.Build.Construction.SolutionProjectGenerator.CreateTraversalInstance(String wrapperProjectToolsVersion, Boolean explicitToolsVersionSpecified, List`1 projectsInOrder)
   at Microsoft.Build.Construction.SolutionProjectGenerator.CreateSolutionProject(String wrapperProjectToolsVersion, Boolean explicitToolsVersionSpecified)
   at Microsoft.Build.Construction.SolutionProjectGenerator.Generate()
   at Microsoft.Build.Execution.ProjectInstance.GenerateSolutionWrapper(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, BuildEventContext projectBuildEventContext, IReadOnlyCollection`1 targetNames, ISdkResolverService sdkResolverService, Int32 submissionId)
   at Microsoft.Build.Execution.ProjectInstance.LoadSolutionForBuild(String projectFile, PropertyDictionary`1 globalPropertiesInstances, String toolsVersion, BuildParameters buildParameters, ILoggingService loggingService, BuildEventContext projectBuildEventContext, Boolean isExplicitlyLoaded, IReadOnlyCollection`1 targetNames, ISdkResolverService sdkResolverService, Int32 submissionId)
   at Microsoft.Build.Execution.BuildManager.LoadSolutionIntoConfiguration(BuildRequestConfiguration config, BuildRequest request)
   at Microsoft.Build.Execution.BuildManager.HandleNewRequest(Int32 node, BuildRequestBlocker blocker)
   at Microsoft.Build.Execution.BuildManager.IssueBuildSubmissionToScheduler(BuildSubmission submission, Boolean allowMainThreadBuild)
   at Microsoft.Build.Execution.BuildManager.<>c__DisplayClass70_0.<ExecuteSubmission>b__0()
   at Microsoft.Build.Execution.BuildManager.ProcessWorkQueue(Action action)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Build.Execution.BuildManager.EndBuild()
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)

MSBUILD : error MSB1025: An internal failure occurred while running MSBuild.
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)

Unhandled Exception: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Target Build already exists.
   at Microsoft.Build.CommandLine.MSBuildApp.BuildProject(String projectFile, String[] targets, String toolsVersion, Dictionary`2 globalProperties, Dictionary`2 restoreProperties, ILogger[] loggers, LoggerVerbosity verbosity, DistributedLoggerRecord[] distributedLoggerRecords, Boolean needToValidateProject, String schemaFile, Int32 cpuCount, Boolean enableNodeReuse, TextWriter preprocessWriter, Boolean detailedSummary, ISet`1 warningsAsErrors, ISet`1 warningsAsMessages, Boolean enableRestore, ProfilerLogger profilerLogger, Boolean enableProfiler, Boolean interactive, Boolean isolateProjects, Boolean graphBuild, String[] inputResultsCaches, String outputResultsCache)
   at Microsoft.Build.CommandLine.MSBuildApp.Execute(String commandLine)
   at Microsoft.Build.CommandLine.MSBuildApp.Main()

@danmoseley
Copy link
Member

The workaround is to not have targets with the default names like Build in a before targets file.

@rainersigwald rainersigwald changed the title MSB0001: Internal MSBuild Error: Target Build already exists. Defining Build target in before.Solution.sln.targets causes hang, MSB0001 Jan 27, 2020
@rainersigwald rainersigwald added bug Area: Solution (.sln) Issues related to parsing .sln files or building solutions regression labels Jan 27, 2020
@rainersigwald rainersigwald added this to the MSBuild 16.5 Preview 3 milestone Jan 27, 2020
@rainersigwald
Copy link
Member

Probably a regression from #4694. Thanks for the report!

Unfortunately, I suspect that the reason the targets were defined there is as a workaround for the bug fixed by that PR, so there may not be an easy works-in-all-versions situation. Worst case, I'd define the stub targets in an import conditioned on '$(MSBuildVersion)' < '16.4.0'. That's if you can't move all your devs and build infrastructure to 16.4+ immediately.

@Forgind Forgind self-assigned this Feb 3, 2020
Forgind added a commit that referenced this issue Feb 12, 2020
* Prevent duplicate targets

Duplicate targets break the build; this prevents MSBuild's default targets from being added if they already exist.

Fixes #5071
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Solution (.sln) Issues related to parsing .sln files or building solutions bug regression triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants