尝试生成新组件时

尝试生成新组件时

本文介绍了Angular 6“工作空间在使用之前需要加载".尝试生成新组件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用angular dotnet创建asp.net核心项目时,新命令不会向项目添加angular.json文件(角度6),因此我们无法使用angular cli.如果我手动添加angular.json文件,则该项目在下面给出异常!

when I create asp.net core project with angular dotnet new command does not add an angular.json file (angular 6) to the project and therefor we are not able to use angular cli. If i add angular.json file manually the project give the exception below!?

Workspace needs to be loaded before it is used. Error: Workspace needs to be loaded before it is used. at Workspace._assertLoaded (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:59:19) at Workspace.getProjectByPath (D:\NetAngular\node_modules\@angular-devkit\core\src\workspace\workspace.js:103:14) at Object.getPackageManager (D:\NetAngular\node_modules\@angular\cli\utilities\config.js:97:35) at UpdateCommand.runSchematic (D:\NetAngular\node_modules\@angular\cli\models\schematic-command.js:74:38) at UpdateCommand.<anonymous> (D:\NetAngular\node_modules\@angular\cli\commands\update.js:70:25) at Generator.next (<anonymous>) at D:\NetAngular\node_modules\@angular\cli\commands\update.js:7:71 at new Promise (<anonymous>) at __awaiter (D:\NetAngular\node_modules\@angular\cli\commands\update.js:3:12) at UpdateCommand.run (D:\NetAngular\node_modules\@angular\cli\commands\update.js:69:16)

推荐答案

EUREKA ..........

EUREKA.............

dotnet新的有角命令不会在应用程序的根目录上创建angular.json文件.在某些网站上,他们说使用

dotnet new angular comman does not create an angular.json file on the root of the application. in some sites they say that after using

npm install --save--dev @angular/cli@latest

命令使用

npm update @angular/cli

这会将您的angular-cli.json文件迁移到angular.json文件!!!但这里的要点是没有angular-cli.json文件也没有angular.json.

which will migrate you angular-cli.json file to angular.json file!!! but the point here there is no angular-cli.json file nor angular.json.

我通过以下方式创建我自己的angular.json文件来解决此问题(您可以使用项目名称更改vega)

I solved the problem by creating my own angular.json file as bellow (you may change vega with your project name)

 {
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "vega": {
      "root": "",
      "sourceRoot": "ClientApp",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "ClientApp/dist/vega"
          },
          "configurations": {
            "production": {
              "fileReplacements": [{
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
              }],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true
            }
          }
        }
      }
    }
  }
}

之后,我能够使用angular cli命令并创建组件和服务.

after that i was able to use angular cli command and create components and services.

这篇关于Angular 6“工作空间在使用之前需要加载".尝试生成新组件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 20:27