【问题标题】:Using Type Script w/ ASP.Net Core build errors from .xproj file使用带有 .xproj 文件的 ASP.Net Core 构建错误的 Type Script
【发布时间】:2017-05-15 18:12:02
【问题描述】:

我正在开发一个新的 ASP.Net Core 项目,我已经 followed a blog post 使用 Angular 2 和 Type Script 设置它。一旦我将 Type Script 文件添加到我的项目中,我的 xproj 文件中就会出现以下构建错误。

我做错了什么吗?这是我的 project.json、package.json 和 systemjs.config.js 以及项目中唯一的 Type Script 文件。

project.json

{
  "title": "Manage Care Web",
  "userSecretsId": "ManageCare-Apps-Web-c23d27a4-eb88-4b18-9b77-2a93f3b15119",

  "dependencies": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration": "1.1.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
    "Microsoft.Extensions.Configuration.Json": "1.1.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.1.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.1.0",
    "Microsoft.Extensions.Logging.Debug": "1.1.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.1.0",
    "BundlerMinifier.Core": "2.2.306",
    "Microsoft.ApplicationInsights.AspNetCore": "1.0.2",
    "Microsoft.AspNetCore.Diagnostics": "1.1.0",
    "Microsoft.AspNetCore.Identity": "1.1.0",
    "Microsoft.AspNetCore.Mvc": "1.1.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
    "Microsoft.AspNetCore.StaticFiles": "1.1.0",
    "Microsoft.NETCore.App": "1.1.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final",
    "OpenIddict": "1.0.0-*",
    "OpenIddict.EntityFrameworkCore": "1.0.0-*",
    "OpenIddict.Mvc": "1.0.0-*",
    "Security.AspIdentity": "1.0.0-*",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0",
    "Security.Jwt": "1.0.0-*"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "DataAccess.Abstraction": {
          "target": "project"
        },
        "DataAccess.SqlServer": {
          "target": "project"
        },
        "Domain.Provider": {
          "target": "project"
        },
        "Domain.Security": {
          "target": "project"
        },
        "Security.Abstractions": {
          "target": "project"
        },
        "Services.Abstractions": {
          "target": "project"
        },
        "Services.Provider": {
          "target": "project"
        }
      },
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "runtimes": {
    "win10-x64": {},
    "win7-x64": {}
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "Areas/**/Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}

package.json

{
  "version": "1.0.0",
  "name": "managecare",
  "private": true,
  "scripts": {
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "dependencies": {
    "@angular/common": "^2.4.1",
    "@angular/compiler": "^2.4.1",
    "@angular/core": "^2.4.1",
    "@angular/forms": "^2.4.1",
    "@angular/http": "^2.4.1",
    "@angular/platform-browser": "^2.4.1",
    "@angular/platform-browser-dynamic": "^2.4.1",
    "@angular/router": "^3.4.1",
    "core-js": "^2.4.1",
    "jquery": "^3.1.1",
    "reflect-metadata": "^0.1.9",
    "rxjs": "^5.0.2",
    "systemjs": "^0.19.41",
    "zone.js": "^0.7.4"
  },
  "devDependencies": {
    "concurrently": "3.0.0",
    "gulp": "^3.9.1",
    "gulp-cssmin": "0.1.7",
    "gulp-uglify": "2.0.0",
    "gulp-concat": "2.6.1",
    "rimraf": "2.5.4",
    "typescript": "2.0.3",
    "typings": "1.4.0"
  }
}

systemjs.config.js

/**
 * System configuration for Angular samples
 * Adjust as necessary for your application needs.
 */
(function (global) {
    System.config({
        paths: {
            // paths serve as alias
            'npm:': 'libs/'
        },
        // map tells the System loader where to look for things
        map: {
            // our app is within the app folder
            app: 'app',
            // angular bundles
            '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
            '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
            '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
            '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
            '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
            '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
            '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
            '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
            // other libraries
            'rxjs': 'npm:rxjs',
        },
        // packages tells the System loader how to load when no filename and/or no extension
        packages: {
            app: {
                main: './ClientApp.js',
                defaultExtension: 'js'
            },
            rxjs: {
                defaultExtension: 'js'
            }
        }
    });
})(this);

typings.config

{
  "globalDependencies": {
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "jasmine": "registry:dt/jasmine#2.2.0+20160621224255",
    "node": "registry:dt/node#6.0.0+20160909174046"
  }
}

tsconfig.json

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules"
  ]
}

ClientApp.ts

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// import { AppModule } from './App/app.module';

const platform = platformBrowserDynamic();

// platform.bootstrapModule(AppModule);

这个设置我做错了什么?我以前从未使用过 Type Script,但我的印象是这在 Visual Studio 中是开箱即用的。除了我链接到的博客文章中描述的内容之外,我还需要做更多的事情吗?

更新

我按照匿名用户的建议安装了 Typings npm 包,但是当我运行 typings install dt~core-js --global --save 时出现以下异常。

C:\Users\Sully\AppData\Roaming\npm\node_modules\typings\node_modules\typings-core\node_modules\strip-bom\index.js:2 模块.exports = x => { ^^

SyntaxError: Unexpected token => 在exports.runInThisContext (vm.js:73:16) 在 Module._compile (module.js:443:25) 在 Object.Module._extensions..js (module.js:478:10) 在 Module.load (module.js:355:32) 在 Function.Module._load (module.js:310:12) 在 Module.require (module.js:365:17) 在需要(module.js:384:17) 在对象。 >

(C:\Users\Sully\AppData\Roaming\npm\node_modules\typings\node_modules\typings-core\dist\utils\fs.js:5:16) 在 Module._compile (module.js:460:26) 在 Object.Module._extensions..js (module.js:478:10)

【问题讨论】:

    标签: asp.net angularjs typescript


    【解决方案1】:

    请安装 nuget 包:angularjs.TypeScript.DefinitelyTyped https://www.nuget.org/packages/angularjs.TypeScript.DefinitelyTyped

    在 'typings.json' 文件中添加以下内容,对我来说效果很好:

            {
              "globalDependencies": {
                "core-js": "registry:dt/core-js#0.0.0+20160725163759",
                "node": "registry:dt/node#6.0.0+20160831021119"
              }
            }
    

    下面是我的“tsconfig.json”文件:

                {
                  "compilerOptions": {
                    "noImplicitAny": true,
                    "noEmitOnError": true,
                    "removeComments": false,
                    "sourceMap": true,
                    "target": "es5",
                    "module": "commonjs",
                    "moduleResolution": "node",
                    "skipLibCheck": false,
                    "emitDecoratorMetadata": true,
                    "experimentalDecorators": true,
                    "lib": [ "es2015", "dom" ],
                    "types": ["node","js-base64"]
                  },
                  "exclude": [
                    "node_modules",
                    "wwwroot"
                  ],
                  "compileOnSave": false
                }
    

    如果还没有完成,也尝试运行以下:

         typings install dt~core-js --global --save
    

    【讨论】:

    • 我也有那个,没用。
    • 您是否在项目中添加了 typings.json 文件?另外,您是否手动运行 npm install ?因为有时它不会在保存时恢复包。
    • 我有一个 Angular 提到的 typings.config 文件。如何确定 typings.json 文件中的内容?
    • 当我运行typings 命令时出现异常,我用异常详细信息更新了我的 OP。我还更新了我的 tsconfig.json 以匹配你的,但它没有解决问题。我的 Typings 包是本地安装的,我是全局安装的。似乎没有什么不同。
    猜你喜欢
    • 2017-11-01
    • 1970-01-01
    • 2018-03-28
    • 2019-08-14
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 2017-09-09
    相关资源
    最近更新 更多