简体   繁体   English

将现有的asp.net core 2.1角度应用程序转换为Angular 6和Angular CLI 6

[英]Convert existing asp.net core 2.1 angular app to Angular 6 and Angular CLI 6

I created an asp.net core 2.1 angular web app which is come with 5.2 Angular. 我创建了5.2 Angular附带的asp.net core 2.1 angular Web应用程序。 I would like to upgrade to angular 6 and Angular CLI 6. These are the steps I did: 我想升级到angular 6和Angular CLI6。这些是我做的步骤:

  1. Create project in VS2017 .net 2.1 Angular 在VS2017 .net 2.1 Angular中创建项目
  2. npm install npm安装
  3. ng update --all ng update --all
  4. ng update @angular/cli ng update @ angular / cli
  5. create angular.json 创建angular.json
  6. added "@angular-devkit/build-angular": "~0.6.0", to dev dependencies 为开发依赖项添加了“ @ angular-devkit / build-angular”:“〜0.6.0”
  7. npm install npm安装
  8. ng build --prod (this threw error say "Unknown option: --extractCss" ng build --prod(此错误提示“未知选项:--extractCss”
  9. removed --extractCss from package.json 从package.json中删除了--extractCss
  10. Run application from VS2017. 从VS2017运行应用程序。 Application loads up but css is not loading 应用程序已加载但CSS未加载
  11. when I try to deploy to azure web app application does not load. 当我尝试部署到Azure Web应用程序时,应用程序无法加载。

Not sure what other steps I am missing 不知道我还缺少什么其他步骤

Sample project link https://github.com/tkumark/WebApplication3 示例项目链接https://github.com/tkumark/WebApplication3

在此处输入图片说明

Update your angular.json to force extractCss on build and don't miss to add bootstrap as style dependency: 更新您的angular.json以强制在构建时进行extractCss ,不要错过添加bootstrap作为样式依赖项:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "your-app": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "extractCss": true,
            "styles": [
              "src/styles.css",
              "node_modules/bootstrap/dist/css/bootstrap.min.css"
            ],

Check the configuration section as well: 还要检查配置部分:

"configurations": {
            "production": {
...
              "extractCss": true
            "debug": {
...

The angular.json schema can be found here : https://github.com/angular/angular-cli/wiki/angular-workspace 可以在这里找到angular.json模式: https : //github.com/angular/angular-cli/wiki/angular-workspace

You also need to check if the SPA static files root path match the out path of your angular.json : 您还需要检查SPA静态文件的根路径是否与angular.json的out路径匹配:

Startup.cs 启动文件

// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
    configuration.RootPath = "ClientApp/dist";
});

angular.json angular.json

"outputPath": "dist",

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

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