I just installed Visual Studio Code 1.28.1, but I'm unable to associate it with the .txt extension on Windows 10.

I'm well aware how to associate an extension with an application on Windows. I can right-click in Explorer, select, "Open As...", select the application, and make sure "Always open with this app" is checked. Or I can go in to the properties of a file in Explorer, look at "Opens with", and click on "Change". Or I can go to "Choose default apps by file type …", etc. The problem is that none of this is working with VS Code.

Currently my .txt files are associated with EmEditor. I change the association to Notepad. No problem. I change the association back to EmEditor. That works.

But if I select the blue "Visual Studio Code" option that appears in the list of applications, nothing changes. The old association remains.

I even tried ignoring the blue icon in the selection list, and manually browsed and selected %LocalAppData%\Programs\Microsoft VS Code\Code.exe as the default editor. That doesn't work, either. Nor did manually selecting %LocalAppData%\Programs\Microsoft VS Code\bin\code.cmd.

In case you think this might be related to EmEditor, I tried to associate .tidyconfig files (which on my system are currently not associated with any editor at all) with VS Code. It did nothing.

What's going on? Associating VS Code with my text files should be the most basic of basic Windows integration. Why won't it work?

(I filed this as VSCode Issue #61084, but I had no responses. I'm filing it here in case the "bug" is some sort of user error.)

  • Did you try to run the command manually per command line, like "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "sometxt.txt"? – musicman Oct 17 '18 at 17:23
  • What does that have to do with associating the application with the file type via extension in Windows Explorer? – Garret Wilson Oct 17 '18 at 17:30
  • To see if it is working at all to open the textfile with this application? You might also want to inspect and share the contents of your win registry regarding the file type association. – musicman Oct 17 '18 at 17:37
  • Yes, I can edit text files just fine. The editor is working fine. This question is about association with a file type based upon extension in Windows Explorer. Have you personally tried to associate Visual Studio Code 1.28.1 with the .txt extension in Windows 10? What was the result for you? Did you succeed? – Garret Wilson Oct 17 '18 at 17:39
  • 1
    Possible duplicate of SSMS wont give up file associations – Scott Nov 11 '18 at 17:42

This isn't user error or a Code bug. Microsoft have broken how file associations work in the latest alpha. I found a workaround which works in Windows 10 Pro - Version 1803 - OS Build 17134.320.

Find the command to start Visual Studio Code with a named file: click Start, type "code", right click Visual Studio Code and select Open File Location.

Right click the shortcut, click Properties and copy the contents of Target. This will be something like "C:\Users\[your name]\AppData\Local\Programs\Microsoft VS Code\Code.exe" "%1"

In Registry Editor, create HKEY_CLASSES_ROOT/.txt and set Default to txt_auto_file. Now create HKEY_CLASSES_ROOT/txt_auto_file/shell/open/command and set Default to the text you copied from Target.

At this point you can stop because double clicking a .txt file will now open it in Code. However the icon in Explorer is wrong. Right click the .txt file and select Open With. You'll now find everything works as it should; you can tick Always Use and this will fix the icon.

  • At github.com/Microsoft/vscode/issues/61084 they also indicated the Windows bug and gave a link to reddit.com/r/windows/comments/9qeijs/… for more discussion. I haven't tried your workaround because for now I want to wait for the Windows fix, but thanks. I've upvoted the answer. If someone else reports that this workaround works, I can mark this as the correct answer. – Garret Wilson Nov 1 '18 at 0:05
  • Odd, I got an email saying my bounty had expired, but I don't remember whether I put a bounty on this or not; I guess I did, based on my current reputation. But I don't see anything about a bounty, even though it is supposedly still in the grace period. – Garret Wilson Nov 1 '18 at 0:07
  • @GarretWilson - You started the bounty on Oct 19 at 21:06 which would have expired 7 days later. 50% of the bounty goes to the answer with the most votes cast after the bounty was started. 100% would have gone to the answer you selected. However, no answer received votes during those 7 days, so the bounty wasn’t awarded to answer in this case (there is a minimum number of votes that must be given to an answer) – Ramhound Nov 1 '18 at 5:52
  • Yes, I'm quite experienced using the bounty system on Stack Overflow. But oddly I don't see any option to assign the bounty here, even though I'm in the grace period. Maybe my reputation is so low on Super User that I'm not allowed to assign my own bounty during the grace period. Odd. – Garret Wilson Nov 1 '18 at 14:36
  • @GarretWilson - Your bounty expired several days ago (as of Nov 1). So it’s likely you attempted to award it after it expired – Ramhound Nov 5 '18 at 2:41

Right-click on .txt file and select "Open with" worked for me:


enter image description here

enter image description here

  • That was a lot of work you went to, but you're just repeating the obvious. In fact the question made clear I had already tried this. In this case there was a Windows 10 bug that prevented association, and it was only fixed in the last couple of months. – Garret Wilson Jan 24 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.