且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有构建“错误"的情况下将Angular-CLI与Visual Studio 2017结合使用

更新时间:2022-11-03 13:37:27

结果是,由于angular-cli使用其自身的配置文件进行构建,因此可以安全地修改Microsoft在构建之前检查的tsconfig.json文件.我的解决方案是按如下方式修改tsconfig.json:

Turns out, since angular-cli uses it's own configuration file for builds, it's safe to modify the tsconfig.json file that Microsoft checks before builds. My solution was to modify my tsconfig.json as follows:

{
  "exclude": [
    "node_modules/*",
    "src/*",
    "app/*",
    "@angular/*",
    "package.json"
  ],
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./wwwroot",
    ...
    "experimentalDecorators": true,
    "target": "es6",
  ...
  },
  "ignoreRules": {
    "TS2307": true,
    "TS2304": true,
    "TS2693": true
  }
}

有效地阻止Visual Studio编译,而是默认为ng-build(它本身配置为输出到wwwroot),当在Visual Studio中单击运行"按钮时,效果也很好.

Effectively blocking Visual Studio compilation and instead defaulting to ng-build (which itself is configured to output to wwwroot) Which also plays nice when hitting the "run" button in Visual Studio.

.csproj

<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>

...

  <Target Name="DebugRunWebpack" BeforeTargets="Build">
    <!-- Ensure Node.js is installed -->
    <Exec Command="node --version" ContinueOnError="false">
      <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." />
    <Exec Command="npm install" />
    <Exec Command="ng build --env=$(Configuration)" />
  </Target> 

angular-cli.json

angular-cli.json

"apps": [
    {
      "root": "src",
      "outDir": "wwwroot",
...

还有一件事...

您还必须在Startup.cs文件中设置默认路径:

You'll also have to set the default path in your Startup.cs file:

 context.Request.Path = "/index.html";