如何通过Visual Studio部署带有ASP.NET Core和Angular的应用程序。

huangapple go评论58阅读模式
英文:

How to deploy app with ASP.NET Core and Angular through Visual Studio

问题

我已经按照这个教程操作了:https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-angular?view=vs-2022

我创建了一个包含后端ASP.NET Core和Angular客户端应用程序的解决方案。

对于发布,我尝试将其发布到一个文件夹和一个远程IIS服务器,但在这两种情况下,只有ASP.NET被打包。在发布输出中,我看到Angular应用正在构建,并且我可以从Visual Studio运行两者,但它只是不会将文件打包到发布中。

我还尝试将Angular的输出设置为后端应用的wwwroot文件夹,但没有任何效果。

英文:

I have followed this tutorial: https://learn.microsoft.com/en-us/visualstudio/javascript/tutorial-asp-net-core-with-angular?view=vs-2022

I have created a solution containing a backend ASP.NET Core and angular client application.

For publish, I tried publishing to a folder and to a remote IIS server, but in both instances, only the ASP.NET is packed. In the publish output, I see that the angular app is being built, and I can run both from Visual Studio, but it just doesn't pack the files in the publish.

I also tried setting the output of angular into wwwroot folder of the backend app, it didn't do anything.

答案1

得分: 1

如果你的前端Angular项目没有被发布,你可以手动以生产模式构建Angular项目,然后将dist文件夹的内容复制到你的wwwroot文件夹中。
另外,你是否配置了你的.NET项目以从wwwroot文件夹中提供Angular服务?
你可以在Startup.cs文件中像这样配置它 -

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});
英文:

If your frontend Angular project does not get published, you can manually build the Angular project in Production mode and copy the contents of dist folder to your wwwroot folder.
Also, did you configure your .NET project to serve ANgular from wwwroot folder?
You can do it like this in your Startup.cs file -

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";
    if (env.IsDevelopment())
    {
        spa.UseAngularCliServer(npmScript: "start");
    }
});

huangapple
  • 本文由 发表于 2023年3月12日 16:31:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/75711908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定