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

Bes*_*nna 5 c# visual-studio typescript angular-cli angular

我遇到的问题是在一个包含许多项目的解决方案中(其中一个是针对es5的angular-cli项目),因为微软开发了Typescript,他们非常渴望在不完全了解angular-cli故事的情况下尝试编译.因此,(TS)错误令人沮丧地在构建之间频繁出现并隐藏本来是有效错误的内容.

如何确保Visual Studio将忽略这些Typescript错误,而不是在所有后期构建时显示它们?

Bes*_*nna 7

事实证明,由于angular-cli使用它自己的构建文件配置文件,因此修改tsconfig.jsonMicrosoft在构建之前检查的文件是安全的.我的解决方案是修改我tsconfig.json的如下:

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

有效地阻止Visual Studio编译,而不是默认为ng-build(它本身被配置为输出到wwwroot)当在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> 
Run Code Online (Sandbox Code Playgroud)

角cli.json

"apps": [
    {
      "root": "src",
      "outDir": "wwwroot",
...
Run Code Online (Sandbox Code Playgroud)

还有一件事...

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

 context.Request.Path = "/index.html";
Run Code Online (Sandbox Code Playgroud)

  • 在tsconfig文件中,可能只显示所做的更改.如果不在本地打开文件,很难看到确切的变化 (2认同)