简体   繁体   English

Visual Studio 22 多个启动项目

[英]Visual Studio 22 Multiple Startup Projects

I`m using VS 2022 Professional 2022 (17.2.0).我正在使用 VS 2022 Professional 2022 (17.2.0)。

I wanted to create a ASP.Net Core app with Angular in VS and used the Microsoft Tutorial for it.我想在 VS 中使用 Angular 创建一个 ASP.Net Core 应用程序,并为此使用了 Microsoft 教程。 https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-angular?view=vs-2022 https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-angular?view=vs-2022

When I want to start Multiple Project as once, only Angular CLI will start the ng start command, but the ASP.NET Core Project will never start.当我想一次启动多个项目时,只有 Angular CLI 会启动 ng start 命令,但 ASP.NET Core 项目永远不会启动。 When I disable the Angular Project inside, Multiple Startprojects, the.Net Core Console will start.当我在里面禁用 Angular Project 时,Multiple Startprojects,.Net Core Console 将启动。

Creation started...
1>------ Build started: Project: ConverterBackend, Configuration: Debug Any CPU ------
2>------ Build started: Project: Converter, Configuration: Debug Any CPU ------
1>Analyzer tools are skipped to speed up the build. You can run the Build or Rebuild command to run the analyzer.
1>ConverterBackend -> C:\Optimization\Converter\ConverterBackend\bin\Debug\net6.0\ConverterBackend.dll
3>------ Deployment started: Project: Converter, Configuration: Debug Any CPU ------

Settings:设置:

多个项目启动 配置管理器

.NET 调试设置 视觉工作室栏

proxy.conf.js代理.conf.js

target: "https://localhost:7049",

launchSettings.json启动设置.json

"applicationUrl": "https://localhost:7049;https://localhost:5001",

I hope somebody has a Solution or run into the same Error once, cause I cant find anything about this.我希望有人有解决方案或遇到过同样的错误一次,因为我找不到任何相关信息。 Could this be an AV problem?这可能是 AV 问题吗?

Solution: If u ever run into this Problem Check Script Execution permissions and if the AV blocks something.解决方案:如果您遇到此问题,请检查脚本执行权限以及 AV 是否阻止了某些内容。

I was also struggling with this and finally found a solution thanks to this user .我也在为此苦苦挣扎,最终找到了解决方案,感谢这位用户 It might not be viable for everyone since it requires a version downgrade but I'll share it: I was using Node.js v18.12.1 (LTS at the time) (64-bit).它可能不适合所有人,因为它需要版本降级,但我会分享它:我使用的是 Node.js v18.12.1(当时是 LTS)(64 位)。 I had installed it with nvm for Windows .我已经用nvm for Windows安装了它。 With this set up, OP problem is reproduced.通过此设置,重现了 OP 问题。

Then, I used nvm to switch to Node v16.18.1 (64-bit).然后,我使用 nvm 切换到 Node v16.18.1(64 位)。 With this change the frontend and backend run perfect as expected from the tutorial.通过此更改,前端和后端将按照教程中的预期完美运行。

Edit:编辑:

Another solution to avoid the downgrade is keep using Node.js v18.12.1 and just add --host 0.0.0.0 to the start command in Angular package.json :避免降级的另一种解决方案是继续使用 Node.js v18.12.1 并将--host 0.0.0.0添加到 Angular package.jsonstart命令中:

"start": "ng serve --host 0.0.0.0 --ssl --ssl-cert %APPDATA%\\ASP.NET\\https\\%npm_package_name%.pem --ssl-key %APPDATA%\\ASP.NET\\https\\%npm_package_name%.key"

This works but I can't provide an explanation for why.这行得通,但我无法解释原因。 But it requires adding a rule to the Windows firewall (you probably get a prompt asking you for permission).但它需要向 Windows 防火墙添加规则(您可能会收到一个提示,要求您提供许可)。

I use two instances of VS open for this;我为此使用了两个 VS open 实例; each with a different start up project.每个都有不同的启动项目。

You have to start the ASP.Net Core app.您必须启动 ASP.Net Core 应用程序。 In there you should have a Startup Class.在那里你应该有一个启动类。 Go to Configure Services and add something like this:转到配置服务并添加如下内容:

services.AddSpaStaticFiles(configuration => { configuration.RootPath = "WebUI"; }); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "WebUI"; });

Then the Kestrel Server should start up with the SPA.然后 Kestrel 服务器应该与 SPA 一起启动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM