.net Msbuild尝试生成msbuild.exe而不是我的.csproj文件

tjrkku2a  于 2023-03-20  发布在  .NET
关注(0)|答案(2)|浏览(248)

我在虚拟机上安装msbuild时遇到问题。
我正在使用:

  • Visual Studio 2022社区版
  • .Net框架v4.8.1
  • msbuild版本MSBuild version 17.5.0+6f08c67f3 for .NET Framework - 17.5.0.10706
  • windows 10

如果我创建一个新的“Hello World”C#项目(.Net Framework v4.8.1),那么它将不会生成。
Visual Studio在顶部显示错误:

错误为:

=====================
16-03-2023 18:59:11
Recoverable
Microsoft.Build.Framework.InternalErrorException: MSB0001: Internal MSBuild Error: Cannot acquire required number of nodes.
=============
System.AggregateException: One or more errors occurred. ---> Microsoft.Build.BackEnd.NodeFailedToLaunchException: Den angivne fil blev ikke fundet
   at Microsoft.Build.BackEnd.NodeLauncher.StartInternal(String msbuildLocation, String commandLineArgs)
   at Microsoft.Build.BackEnd.NodeLauncher.DisableMSBuildServer(Func`1 func)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>g__StartNewNode|2(Int32 nodeId)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>b__0(Int32 nodeId)
   --- End of inner exception stack trace ---
---> (Inner Exception #0) Microsoft.Build.BackEnd.NodeFailedToLaunchException: Den angivne fil blev ikke fundet
   at Microsoft.Build.BackEnd.NodeLauncher.StartInternal(String msbuildLocation, String commandLineArgs)
   at Microsoft.Build.BackEnd.NodeLauncher.DisableMSBuildServer(Func`1 func)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>g__StartNewNode|2(Int32 nodeId)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>b__0(Int32 nodeId)<---

 ---> System.AggregateException: One or more errors occurred. ---> Microsoft.Build.BackEnd.NodeFailedToLaunchException: Den angivne fil blev ikke fundet
   at Microsoft.Build.BackEnd.NodeLauncher.StartInternal(String msbuildLocation, String commandLineArgs)
   at Microsoft.Build.BackEnd.NodeLauncher.DisableMSBuildServer(Func`1 func)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>g__StartNewNode|2(Int32 nodeId)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.<>c__DisplayClass14_0.<GetNodes>b__0(Int32 nodeId)
   --- End of inner exception stack trace ---
   --- End of inner exception stack trace ---
   at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Exception innerException, Object[] args)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProcBase.GetNodes(String msbuildLocation, String commandLineArgs, Int32 nextNodeId, INodePacketFactory factory, Handshake hostHandshake, NodeContextCreatedDelegate createNode, NodeContextTerminateDelegate terminateNode, Int32 numberOfNodesToCreate)
   at Microsoft.Build.BackEnd.NodeProviderOutOfProc.CreateNodes(Int32 nextNodeId, INodePacketFactory factory, Func`2 configurationFactory, Int32 numberOfNodesToCreate)
   at Microsoft.Build.BackEnd.NodeManager.AttemptCreateNode(INodeProvider nodeProvider, NodeConfiguration nodeConfiguration, Int32 numberOfNodesToCreate)
   at Microsoft.Build.BackEnd.NodeManager.CreateNodes(NodeConfiguration configuration, NodeAffinity nodeAffinity, Int32 numberOfNodesToCreate)
   at Microsoft.Build.Execution.BuildManager.PerformSchedulingActions(IEnumerable`1 responses)
   at Microsoft.Build.Execution.BuildManager.<>c__DisplayClass95_0.<IssueBuildRequestForBuildSubmission>g__IssueBuildSubmissionToSchedulerImpl|1(BuildSubmission submission, Boolean allowMainThreadBuild)
   at Microsoft.Build.Execution.BuildManager.<>c__DisplayClass95_0.<IssueBuildRequestForBuildSubmission>b__0()
   at Microsoft.Build.Execution.BuildManager.ProcessWorkQueue(Action action)

如果我尝试在Visual studio中从Developer powershell运行msbuild,则出现以下错误:

> msbuild .\ConsoleApp2.csproj
MSBuild version 17.5.0+6f08c67f3 for .NET Framework
MSBUILD : error MSB1008: Only one project can be specified.
    Full command line: '"C:\PROGRA~1\MIB055~1\2022\COMMUN~1\MSBuild\Current\Bin\amd64\MSBuild.exe" "C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64\MSBuild.exe" .\ConsoleApp2.csproj'
  Switches appended by response files:
'' came from 'C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.rsp'
Switch: .\ConsoleApp2.csproj

For switch syntax, type "MSBuild -help"

这看起来很奇怪,它看起来像是试图运行命令。它已经将自己作为自己的参数插入其中。

"C:\PROGRA~1\MIB055~1\2022\COMMUN~1\MSBuild\Current\Bin\amd64\MSBuild.exe" "C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64\MSBuild.exe" .\ConsoleApp2.csproj

如果我尝试只运行msbuild,看起来msbuild正在尝试构建msbuild.exe,显然失败了。

> msbuild
MSBuild version 17.5.0+6f08c67f3 for .NET Framework
Build started 16-03-2023 19:29:57.
Included response file: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.rsp

Project "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe" on node 1 (default targets).
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe(1,1): error MSB4025: The project file could not be loaded. Dataene på rodniveau er ugyldige. linje 1, position 1.
Done Building Project "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe" (default targets) -- FAILED.

Build FAILED.

"C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe" (default target) (1) ->
  C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.exe(1,1): error MSB4025: The project file could not be loaded. Dataene på rodniveau er ugyldige. linje 1, position 1.

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.04

我不知道这个额外的msbuild从哪里来。
我试过:

  • 重新安装Visual Studio 2022
  • 检查环境变量-一切正常
  • 检查文件C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64\MSBuild.rsp-它只包含默认注解

如何修复msbuild,使其能够再次构建项目?

svujldwt

svujldwt1#

对于该特定位置中的特定文件名,可能存在适当的特定规则。
您应该能够通过打开注册表编辑器并更改MSBuild.exe的值来解决此问题。
转到Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options,找到MSBuild.exe的条目并将其删除。
来源:https://answers.microsoft.com/en-us/windows/forum/all/windows-cannot-find-make-sure-you-typed-the-name/6c60a27d-115f-474b-aaf7-2ac3d8367f26?page=1

mklgxw1f

mklgxw1f2#

DictationScratchPad找到的解决方案有效!

我不知道这些键来自哪里,但我在注册表中有以下键。(从注册表中导出之前,我删除它们)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\MSBuild.exe]
"HTag"=dword:00000000
"UseFilter"=dword:00000001

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\MSBuild.exe\0]
"HTag"=dword:00000000
"Debugger"="ntsd -c q"
"FilterFullPath"="C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\amd64\\MSBuild.exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\MSBuild.exe\1]
"HTag"=dword:00000000
"Debugger"="ntsd -c q"
"FilterFullPath"="C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\MSBuild\\Current\\Bin\\MSBuild.exe"

删除它们解决了问题,msbuild现在工作正常。

相关问题