NinjaFisherman
NinjaFisherman

Reputation: 296

Rename a Typescript file

May be I'm missing something on this one (or may be I'm too tired :P ). In Visual Studio 2012 in a Typescript project, when I rename a ts file, instead of rename the js file linked with that ts file, it creates a new one.

Ex :
Old situation : (file1.ts --> file1.js) After renaming : (file1337.ts --> file.js) + file1337.js //file1337 isn't include in project, I need to do it manually ...

So is there a way to rename both the ts file and the js directly linked with this file at the same time without creating a new one and having to manually adding the new js file in the project?

Thanks

Upvotes: 7

Views: 7914

Answers (3)

Andzej Maciusovic
Andzej Maciusovic

Reputation: 4476

This is old question, but in Visual Studio 2015 this problem also exists. In project BuildEvents Pre-build event command line you can insert following code:

del /S /Q "$(ProjectDir)\path\to\ts\code\*.js" && del /S /Q "$(ProjectDir)\path\to\ts\code\*.js.map"

This command will remove all generated .js and .js.map files before project build.

Upvotes: 1

Fenton
Fenton

Reputation: 251152

There is a slight gap in the Visual Studio extension that means renames aren't handled perfectly.

The easiest option is to create a new file with the correct name, move the contents over and delete the old file.

The slightly harder option is to hand-edit the project file after the rename to update the associations.

With Web Essentials, you have a similar issue that the renamed file is associated to the incorrectly named JavaScript and Map file and you'll have to fiddle it to get it to work. It still feels like the cleanest option is to add a new file and transfer the contents rather than rename.

Upvotes: 1

Jude Fisher
Jude Fisher

Reputation: 11284

I've found that if you delete the associated .js file and any source map (that is, delete the files nested inside the .ts in Solution Explorer), then rename the.ts file, then recompile, the .js files are regenerated with the new name, and are automatically added to the project (as long as the .ts file already is).

I should add that I have WebEssentials installed - I don't know how much of this behaviour is due to that, and how much is native to VS.

Upvotes: 5

Related Questions