1

I have a ASP.NET Core project (a .xproj file) containing some TypeScript files. When I build this project, all .ts files are automatically transpiled to .js files. Also if I modify and then save a .ts file its .js is generated (compileOnSave). This is nice.

In the same solution I have a .NET Core Class Library (also a .xproj file). This project also contains a tsconfig.json file and some TypeScript files. The compileOnSave feature works nice, but when I build the project, the .ts files are not compiled. This means that I need to modify and save the .ts file manually to generate the .js file.

How do I have to configure my class library project so that .js files are created when I build the project?

I'm working with Visual Studio 2015 Update 3 with the "TypeScript for Microsoft Visual Studio" version 2.0.6.0 extension installed.

1 Answer 1

1

Add <Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> to the xproj file to get typescript built to JS (got the line from my ASP.NET Core - .xproj file)

Sign up to request clarification or add additional context in comments.

4 Comments

When I open the Property Page of my TypeScript file I cannot set (or see) a build action. Note that I have a .xproj project. Maybe your solution would work for a traditional .csproj project.
You are right. Setting the Build Action for your typescript file (Solution Browser -> Alt + Return) to "TypeScriptCompile" to get it built, was the pre .net Core / csproj way. I updated the answer.
Thanks, this is exactly what I was looking for! I'm just not sure if I should remove the existing Microsoft.DotNet.targets when I add the Microsoft.DotNet.Web.targets. At the moment I have both in my .xproj and it works fine :)
When adding the Microsoft.DotNet.Web.targets, the project type seems to change and also a launchSettings.json gets created. So what I do instead now is adding <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets')"/> to my .jxproj

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.