我的解决方案中有多个项目。主要的两个“可运行”项目是服务器和客户端。 “运行/调试”按钮旁边的下拉列表显示“调试”和“发布”。这似乎是管理多个“项目配置”的“解决方案配置”。我正在寻找一种方法,用“调试客户端”、“发布客户端”、“调试服务器”和“发布服务器”的“解决方案配置”替换它们。 有了这个,我希望只需选择任何配置并点击播放即可构建正确的“项目配置”并运行/调试预期的项目。 但是,我找不到任何设置来决定实际启动哪个项目。仅“构建”/“部署”。 我仍然需要手动选择哪个项目“设置为启动项目”。
我可以在解决方案属性中看到我可以设置多个启动项目。如果我能够更改左上角的“配置”,这个“属性”页面将是绝对完美的,但是整个配置/平台区域呈灰色显示“N/A” ”。我只能在一般级别上更改它,如果我将客户端和服务器都更改为“启动”,那么它们总是启动,这绝对不是我想要的。我只想根据我选择的解决方案配置启动一个。这不可能吗?
最佳答案
我找到了一个名为 SwitchStartupProject 的扩展程序那可以实现你所追求的目标。使用此扩展,您可以配置以 JSON 编写的解决方案启动文件。作为一个例子,我是这样写的:
{
/* Configuration File Version */
"Version": 3,
/* Create an item in the dropdown list for each project in the solution? */
"ListAllProjects": false,
"MultiProjectConfigurations": {
"ProjectA": { /* Configuration name (appears in the dropdown) */
"Projects": {
"ProjectA": {} /* Starting ProjectA */
},
"SolutionConfiguration": "ProjectAConfig", /* Activating solution configuration "ProjectAConfig" */
"SolutionPlatform": "Any CPU" /* and solution platform "Any CPU" */
},
"ProjectB": { /* Configuration name (appears in the dropdown) */
"Projects": {
"ProjectB": {} /* Starting ProjectB */
},
"SolutionConfiguration": "ProjectBConfig", /* Activating solution configuration "ProjectBConfig" */
"SolutionPlatform": "x86" /* and solution platform "x86" */
},
"netcoreapi": { /* Configuration name (appears in the dropdown) */
"Projects": {
"netcoreapi": {} /* Starting netcoreapi*/
},
"SolutionConfiguration": "Debug", /* Activating solution configuration "Debug" */
"SolutionPlatform": "Any CPU" /* and solution platform "Any CPU" */
}
}
}
结果:
您无需更改所需的配置,而是选择要启动的项目,这反过来又可以更改所使用的配置。您甚至可以更改平台以及演示等。查看configuration扩展页面以了解更多信息。
关于visual-studio - 如何根据解决方案配置运行/调试给定项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67660316/