首页 文章

Visual Studio 2015没有将TypeScript编译为ASP.NET Core项目的一部分?

提问于
浏览
4

我正在使用VS2015并且正在尝试使用TypeScript内部的ASP.NET Core项目生成一个Angular应用程序,但无论我尝试什么,我都无法将我的Angular虚拟项目转换为 wwwroot 文件夹,尽管VS2015识别它作为TypeScript虚拟项目 . 这是我的项目结构:

enter image description here

这是我的 tsconfig.json 文件:

{
  "compileOnSave": true,
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "module": "system",
    "experimentalDecorators": true,
    "moduleResolution": "node",
    "outDir": "../../wwwroot/"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

VS不会自动编译,甚至从命令行运行 npm run tsc:w main.ts 会导致找不到文件错误 . 如何构建我的ts文件?

2 回答

  • 0

    @EchoLogic,尝试将Angular文件夹重命名为脚本,它应该可以工作 .

  • 0

    你的outdir是相对于tsconfig.json所以你的路径应该是这样的:../wwwroot/ . 这是我自己的tsconfig.json的一个例子:

    {
    "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outFile": "../wwwroot/app/app.js"
      },
    "compileOnSave": true,
    "files": [
      "../typings/main.d.ts",
      "app.module.ts",
      "app.config.ts",
      "home.controller.ts",
      "myTeam.controller.ts"
      ]}
    

    我也喜欢通过gulp构建打字稿 . 我发布了两篇关于如何做到这一点的文章:

    在这里,您可以找到有关如何配置ASP.NET Core应用程序以编译打字稿的完整分步指南:ASP.NET Core: modify an Angular app to use typescript

    以及如何使用Gulp工作流程:ASP.NET Core: Building Typescript with Gulp

相关问题