Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2013 not adding Javascript generated from Typescript to project automatically

I'm using TypeScript for the first time. I'm using Visual Studio 2013 with update 4, Web Essentials with update 4, and have the latest version of TypeScript from Microsoft's website. However, following the tutorial doesn't work for me: when saving a TS file, it automatically compiles to JavaScript on the screen to the right of the code I typed, and a JS file is created in the folder. However, this file is not added to the project automatically. How can I set Visual Studio 2013 to automatically add generated JS files to the project?

like image 884
yesman Avatar asked Feb 25 '26 23:02

yesman


2 Answers

How can I set Visual Studio 2013 to automatically add generated JS files to the project

Use a glob for your TypeScript folder i.e. modify your .csproj file to include:

<Content Include="client-src\**\*.*">
</Content>
like image 130
basarat Avatar answered Feb 28 '26 16:02

basarat


Besides Basarat's answer which works, there's also another solution: not doing anything. TypeScript generates a JavaScript file, which automatically gets placed in the same folder as the TypeScript file. When in Visual Studio, right click the folder your TypeScript file is in, and select "open folder in file explorer". You should see that the folder holds both the TS file you made, and the JS file that got generated.

You do not need to add this JS file to your project folder inside Visual Studio: you can just reference it. If you have an MVC project with a Scripts folder that has a file called greeting.ts (the one you make in the TypeScript tutorial), the path would be "~/Scripts/greeting.ts". Instead, just use "~/Scripts/greeting.js" (ending with js instead of ts). Visual Studio is smart enough to figure it out from there. This works with bundles as well.

like image 31
yesman Avatar answered Feb 28 '26 17:02

yesman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!