angular - 在 azure 上发布 .net core 2.0 Angular Spa Web 应用程序时出错

标签 angular azure asp.net-core visual-studio-code azure-web-app-service

从今天早上开始,我尝试使用 azure 应用服务 扩展从 Visual Studio 代码发布我的 Angular Spa 应用程序,但是当我尝试导航到该 URL 时,我收到此页面:

enter image description here

我使用此 CLI 命令将文件发布到我的电脑中:

dotnet build -c Release && dotnet publish -c Release --output "./release"

我的 csproj 看起来像这样:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>
    <SpaRoot>ClientApp\</SpaRoot>
    <DefaultItemExcludes>$(DefaultItemExcludes);$(SpaRoot)node_modules\**</DefaultItemExcludes>
    <UserSecretsId>b7354f74-12e8-4958-a0d5-4fdc25e86285</UserSecretsId>

    <!-- Set this to true if you enable server-side prerendering -->
    <BuildServerSideRenderer>false</BuildServerSideRenderer>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1"/>
    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="2.1.1" />
    <PackageReference Include="Gardendynamics.Commons" Version="1.0.0-ci-76" />
    <PackageReference Include="Gardendynamics.Tiers" Version="1.0.0-ci-50" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\PicaplantBack.Database\PicaplantBack.Database.csproj" IncludeAssets="All" />
  </ItemGroup>
  <ItemGroup>
    <!-- Don't publish the SPA source files, but do show them in the project files list -->
    <Content Remove="$(SpaRoot)**" />
    <None Include="$(SpaRoot)**" Exclude="$(SpaRoot)node_modules\**" />
  </ItemGroup>

  <Target Name="DebugEnsureNodeEnv" BeforeTargets="Build" Condition=" '$(Configuration)' == 'Debug' And !Exists('$(SpaRoot)node_modules') ">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="true">
      <Output TaskParameter="ExitCode" PropertyName="ErrorCode" />
    </Exec>
    <Error Condition="'$(ErrorCode)' != '0'" Text="Node.js is required to build and run this project. To continue, please install Node.js from https://nodejs.org/, and then restart your command prompt or IDE." />
    <Message Importance="high" Text="Restoring dependencies using 'npm'. This may take several minutes..." />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm install" />
  </Target>

    <Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
    <!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:preprod" />
    <Exec WorkingDirectory="$(SpaRoot)" Command="npm run build:ssr -- --prod" Condition=" '$(BuildServerSideRenderer)' == 'true' " />

    <!-- Include the newly-built files in the publish output -->
    <ItemGroup>
      <DistFiles Include="$(SpaRoot)dist\**; $(SpaRoot)dist-server\**" />
      <DistFiles Include="$(SpaRoot)node_modules\**" Condition="'$(BuildServerSideRenderer)' == 'true'" />
      <ResolvedFileToPublish Include="@(DistFiles->'%(FullPath)')" Exclude="@(ResolvedFileToPublish)">
        <RelativePath>%(DistFiles.Identity)</RelativePath>
        <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
      </ResolvedFileToPublish>
    </ItemGroup>
  </Target>
</Project>

最佳答案

我遇到了同样的问题,我按照详细信息解决了它,

https://github.com/angular/angular-cli/issues/10666

我遇到的问题是我必须编辑 package.json 文件并从启动和构建属性中删除 --extractCss 参数。来自:

"scripts": {
    "ng": "ng",
    "start": "ng serve --extract-css",

至:

"scripts": {
    "ng": "ng",
    "start": "ng serve",

关于angular - 在 azure 上发布 .net core 2.0 Angular Spa Web 应用程序时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51580837/

相关文章:

angular - 导航到 Azure Blob 存储上的 Angular 9 应用程序的 Azure 函数代理会导致 mime 类型错误

Azure数据工厂: read from csv and copy row by row to a cosmos db

asp.net - 如何在没有用户名或密码的情况下配置与 Azure Database for PostgreSQL 灵活服务器的连接?

Angular2 无法在 promise 中访问 'this'

javascript - 页面加载时隐藏菜单,onclick按钮显示菜单,第一次单击显示,第二次单击隐藏,就像 Angular 4.0中的切换一样

angular - ng-bootstrap 模态的 ElementRef

c# - .Net 核心中 Json() 的小写属性名称

angular - Ionic2 Angular2 : I can't seem to get an ng2-chart to appear in my app

javascript - 逻辑应用绕过筛选器查询中的 Null

c# - 在没有 DI 的情况下登录 .NET Core?