如何在 Azure Devops 版本部署 Azure 静态 Web 应用中找到我的 staticwebapp.config.json?

A. *_* Gh 3 azure-devops angular azure-static-web-app azure-static-web-app-routing

我有一个为我的Angular应用程序构建 artificat 的管道。在我尝试访问特定 URL 之前,部署工作正常。它将我重定向到 404。这与staticwebapp.config.json. 看起来像:

{
  "navigationFallback": {
    "rewrite": "/index.html",
    "exclude": ["*.{css,scss,js,png,gif,ico,jpg,svg}"]
  }
}
Run Code Online (Sandbox Code Playgroud)

我在 Azure Devops 中创建了一个发布管道,将其发布到Azure 上的静态 Web 应用程序。这就是我的.yaml样子:

steps:
- task: AzureStaticWebApp@0
  displayName: 'Static Web App: '
  inputs:
    workingDirectory: '$(System.DefaultWorkingDirectory)/xx/xx/xx-xx-web'
    app_location: /
    output_location: dist
    config_file_location: configuration
    skip_app_build: true
    skip_api_build: true
    is_static_export: false
    verbose: true
    azure_static_web_apps_api_token: 'SOMEVALUE'
Run Code Online (Sandbox Code Playgroud)

staticwebapp.config.json 位于此处:

  • 源代码
    • 应用程序
    • 资产
    • 配置
      • 静态webapp.config.json

这是我在发布过程中遇到的错误:

##[error]routes_location: route file 'staticwebapp.config.json/routes.json' could not be found.
Run Code Online (Sandbox Code Playgroud)

或者当我填写config_file_location

##[error]config_file_location: config file '/configuration/staticwebapp.config.json' could not be found.
Run Code Online (Sandbox Code Playgroud)

我如何找到该文件?

A. *_* Gh 7

这个问题就解决了。我做了以下事情:

staticwebapp.config.json文件应该位于来自构建管道的构建工件中。而且这个文件无处可寻。我所做的是将配置文件放入该assets文件夹中,因为该文件夹在构建过程中完全被接管。解决方案文件中的这段配置angular.json负责:

"assets": [
 "src/favicon.ico",
 "src/assets"
]
Run Code Online (Sandbox Code Playgroud)

它接管资产文件夹内的所有内容。您还可以将确切位置放入此资产数组中,但我保持简单。新构建后,我看到文件夹staticwebapp.config.json中的构建工件中出现了assets

.yaml将其部署到Azure Static Web App现在如下所示:

steps:
- task: AzureStaticWebApp@0
  displayName: 'Static Web App: '
  inputs:
    workingDirectory: '$(System.DefaultWorkingDirectory)/xx/xx/xx-xx-web'
    app_location: /
    output_location: dist
    config_file_location: /assets
    skip_app_build: true
    skip_api_build: true
    is_static_export: false
    verbose: true
    azure_static_web_apps_api_token: 'SOMEVALUE'
Run Code Online (Sandbox Code Playgroud)