How to prevent visual studio 2017 from build javascript?
Simple Answer
In your csproj file, add the following line to the existing PropertyGroup block:
<PropertyGroup> <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked></PropertyGroup>
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>
Add a tsconfig.json
file to your project root and make sure the following setting is set:
"compileOnSave": false,
Finally, Restart Visual Studio
Details
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
.
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>
I'm using webpack's ts-loader to compile and bundle my TypeScript files. So I no longer needed the automatic compilation that Visual Studio performed on each build. In Visual Studio 2017, I just commented out the following line from tsconfig.json to stop the automatic compilation:
"outDir": "./wwwroot/build/",
Setting TypeScriptCompileBlocked
to true
was not enough for me. What worked was going to the project properties - there is a TypeScript Build tab where you can configure TS compilation, including the Compile On Save option:
It results in the following getting added to the csproj
file:
<TypeScriptTarget>ES5</TypeScriptTarget><TypeScriptJSXEmit>None</TypeScriptJSXEmit><TypeScriptModuleKind>ES6</TypeScriptModuleKind><TypeScriptCompileOnSaveEnabled>False</TypeScriptCompileOnSaveEnabled><TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny><TypeScriptRemoveComments>False</TypeScriptRemoveComments><TypeScriptOutFile /><TypeScriptOutDir /><TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations><TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError><TypeScriptSourceMap>True</TypeScriptSourceMap><TypeScriptMapRoot /><TypeScriptSourceRoot />