如何防止 Visual Studio 2017 构建 JavaScript?
我今天升级到 VS2017,我看到每次我在我的 web 应用程序项目中更改一些东西 - 构建再次构建我所有的 javascript(我使用 webpack 作为客户端).这很酷,但需要很多时间,所以我很乐意将它配置为停止构建 javascript(我会在它发生变化时自己构建它).
I upgraded today to VS2017, and I saw that every time I change something in my my web app project - the build build all my javascript again (I'm using webpack for client). It is cool, but it take a lot of time, so I'll be happy to configure it to stop building the javascript (and I'll build it myself just when it changed).
推荐答案
简单回答
在您的 csproj 文件中,将以下行添加到现有的 PropertyGroup 块:
Simple Answer
In your csproj file, add the following line to the existing PropertyGroup block:
<PropertyGroup>
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
</PropertyGroup>
如果将 .ts
或 .tsx
文件添加到您的项目会导致您的项目文件被修改,您可能需要应用以下修复.请参阅 错误报告 了解更多详情.
If adding .ts
or .tsx
files to your project causes your project file to be modified, you may need to apply the following fix. See the bug report for more details.
<ItemGroup>
<None Remove="**/*.ts;**/*.tsx" />
<Content Remove="**/*.ts;**/*.tsx" />
<TypeScriptCompile Include="**/*.ts;**/*.tsx" />
</ItemGroup>
将 tsconfig.json
文件添加到您的项目根目录并确保设置了以下设置:
Add a tsconfig.json
file to your project root and make sure the following setting is set:
"compileOnSave": false,
最后,重启 Visual Studio
Finally, Restart Visual Studio
Nuget 在项目的 obj
目录中创建一个名为 [ProjectName].csproj.nuget.g.targets
的生成目标文件.此目标文件正在导入 Microsoft.NET.Sdk.Web.ProjectSystem.targets
,而后者又会导入 Microsoft.TypeScript.targets
.
Nuget creates a generated targets file called [ProjectName].csproj.nuget.g.targets
in the obj
directory of your project. This targets file is importing Microsoft.NET.Sdk.Web.ProjectSystem.targets
which in turn imports Microsoft.TypeScript.targets
.
在 Microsoft.TypeScript.targets
文件中,以下行有一条注释让我们知道如果此属性设置为 true,那么 TypeScript 编译任务将不执行任何操作:
In the Microsoft.TypeScript.targets
file, the following line has a comment that lets us know that if this property is set to true, then the TypeScript compilation task will do nothing:
<!-- Makes the TypeScript compilation task a no-op -->
<TypeScriptCompileBlocked Condition="'$(TypeScriptCompileBlocked)' == ''">false</TypeScriptCompileBlocked>
相关文章