错误 MSB4126:指定的解决方案配置 "release|any cpu" 无效

Error MSB4126: The specified solution configuration "release|any cpu" is invalid

我已经为我的一个客户端应用程序设置了 devops 流程。它在构建和发布级别上运行良好。但是几天后我的构建突然失败并出现以下错误。

node_modules\uws\build\binding.sln.metaproj(0,0): Error MSB4126: The specified solution configuration "release|any cpu" is invalid. Please specify a valid solution configuration using the Configuration and Platform properties (e.g. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave those properties blank to use the default solution configuration.

谁能告诉我如何解决这个问题?

我认为最好的选择是同时使用多个针对项目组的解决方案(分区解决方案) 这里是 link 以获取更多信息

Partitioned Solution

我也在很多开源项目中实现,这里是其中之一

Project on GitHub using Partitioned Solution

您可以使用 PowerShell 任务 更改 .sln 文件。

假设你要构建除网站项目以外的项目,那么你可以删除.sln文件GlobalSection中的网站项目信息。

先决条件:

获取要移除的项目ID,格式为ECF93D95-5096-497E-B4B8-83416DABB516

然后添加一个 PowerShell 任务 before VS 构建其他项目的任务。脚本为:

git checkout $(BUILD.SOURCEBRANCHNAME)
(get-content "$(Build.SourcesDirectory)\relative\path\to\solution") -notmatch "{project_ID}.$(BuildConfiguration)" | out-file "$(Build.SourcesDirectory)\relative\path\to\solution"

例如从 .sln 文件中删除项目 ECF93D95-5096-497E-B4B8-83416DABB516 的示例:

git checkout $(BUILD.SOURCEBRANCHNAME)
(get-content "$(Build.SourcesDirectory)\ConsoleAppCore\ConsoleAppCore.sln") -notmatch "{ECF93D95-5096-497E-B4B8-83416DABB516}.$(BuildConfiguration)" | out-file "$(Build.SourcesDirectory)\ConsoleAppCore\ConsoleAppCore.sln"

VS Build 任务之后,您可以添加另一个 PowerShell 任务以将更改的 .sln 恢复为 git 存储库中的相同版本。脚本为:

git reset --hard head

对于除其他项目之外的网站项目,可以使用相同的方式跳过项目进行构建。

注意: 对于 PowerShell 任务,请取消选择 Fail on Standard Error 选项。

我在使用 VSTS 时遇到过一次这个问题。我建议你直接使用 MSBuild 参数

Ho 添加到 MSBuild 参数:

/p:Configuration=$(BuildConfiguration) /p:Platform="$(BuildPlatform)"

注意:将平台和配置留空