Annoying: Visual studio plugin modifies a new file after it opens

Topics: General
Aug 9, 2013 at 5:31 AM
When creating a new TypeScript file in Visual Studio 2012, VS opens the new blank file, then modifies it, prompting a modal dialog telling me the file has changed and asking me if I want to reload it. When creating a lot of new files in the early stages of a new project, this is very annoying.

To reproduce:
  1. Right click on a folder in the solution panel
  2. Click Add -> Code File
  3. Enter a .ts filename, e.g. test.ts
  4. New, blank file opens as expected
  5. Visual studio then tells me the file has changed and prompts to reload it
Aug 9, 2013 at 6:04 AM
Strange.. I right-click a folder, pick "Add -> TypeScript File", enter a name and it creates it automatically with no pop-up.

It does fill it with the standard default TS Shape code, but at least it gives you focus so you can just select-all and nuke it. I would rather it didn't create this though. Also quite annoying is that if your project is set to compile to an outfile VS will still link your TS files to JS files, it populates them with the compiled Shape sample code but of course they never change from that point on as when you compile with an outfile the local JS files don't get modified. I wish it could be told not to do either of these things.
Aug 9, 2013 at 8:20 AM
Hmm, I don't have the option to add a "TypeScript File", hence my choice of "Code File". Have you tried to my way, to see if that causes the error?
Aug 9, 2013 at 11:16 AM
I don't have the option to "Add Code File", I suspect you haven't created a TypeScript project within VS, but something else (Web maybe?). If you create a proper TS project it sets is all up as default with an app.ts, default.htm, etc and hooks the app.ts to compile to JS, also sets an ES3 project type. Any of this sound familiar?
Aug 9, 2013 at 3:10 PM
@PhotonStorm Even worse if you use a source control extension (like VisualSVN here) those generated files get automatically added to the repo - which is of course a terrible idea.
Aug 9, 2013 at 3:32 PM
Edited Aug 9, 2013 at 3:32 PM
Try changing the following visual studio setting:

Tools -> Options -> Environment -> Documents -> "Detect when file is changed outside the environment"

Make sure sure "Auto-load changes, if saved" is checked.
Aug 10, 2013 at 9:14 AM
@dmck - I don't want to turn the feature off, it's useful! I want the plugin to behave correctly, i.e. not modify the file after it's created.
Aug 10, 2013 at 9:15 AM
PhotonStorm wrote:
I don't have the option to "Add Code File", I suspect you haven't created a TypeScript project within VS, but something else (Web maybe?). If you create a proper TS project it sets is all up as default with an app.ts, default.htm, etc and hooks the app.ts to compile to JS, also sets an ES3 project type. Any of this sound familiar?
Correct, I am using a general web project which happens to use TypeScript for some areas. Yes, I could go and create an explicit "TypeScript Project", but I'd really prefer that this bug were fixed.