如何定义 对于Visual Studio Publish的Angular项目?

问题描述 投票:0回答:2

我有一个包含Angular版本7项目的.Net Core API项目,因此我不想每次手动更改index.html源代码,

的index.html

<base href="/">

每次我构建开发版本时手动(VS - > href =“/” - > IIS Express)然后通过Visual Studio发布生成生产版本(VS-> href =“/ ProjectName /” - >右键单击项目 - >发布...),我相信它没有意义!

注:当我通过VS发布功能发布和构建角度项目时,我无法访问此命令,

ng build --prod --base-href /ProjectName/ 

或任何不同类型的此命令

我正在寻找一个解决方案来通过配置或类似的东西来处理这个问题。

非常感谢!

angular visual-studio build .net-core publish
2个回答
0
投票

将它添加到package.json以获取构建脚本“build”:

ng build --prod --aot  --base-href /ProjectName/

1
投票

所以基于@savinn解决方案,它的工作很有魅力,我试着再一次解释这个解决方案,

在Angular项目版本7中,我有index.html,就像这样

的index.html

<base href="/">

它适用于在IIS Express(F5)上的开发模式下运行应用程序,

但对于生产模式,您需要像这样定义项目名称

的index.html

  <base href="/ProjectName/">

但是每次都无法更改它并签入源代码,因此基于@savinn解决方案,您可以设置

的package.json

 "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod --aot --base-href /ProjectName/",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

现在,当您通过Visual Studio 2017在IIS上发布项目时,它会运行此ng版本,并且在IIS上发布的index.html文件中,您可以看到此内容

在IIS上发布了index.html,ClientApp \ dist \ index.html

 <base href="/ProjectName/">

因此,在不更改index.html的情况下,您可以将app作为开发模式运行,并通过IIS上的VS发布进行发布。

© www.soinside.com 2019 - 2024. All rights reserved.