unable to associate .txt file with listed Visual Studio Code on Windows 10

2

1

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.)

Garret Wilson

Posted 2018-10-17T16:37:33.550

Reputation: 73

Did you try to run the command manually per command line, like "%LocalAppData%\Programs\Microsoft VS Code\Code.exe" "sometxt.txt"? – musicman – 2018-10-17T17:23:46.157

What does that have to do with associating the application with the file type via extension in Windows Explorer? – Garret Wilson – 2018-10-17T17:30:13.203

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 – 2018-10-17T17:37:06.213

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 – 2018-10-17T17:39:14.447

Possible duplicate. https://superuser.com/questions/1367271/can-notepad-be-replaced-with-vs-code/1367280#1367280

– HazardousGlitch – 2018-10-19T22:37:38.417

@HazardousGlitch, no, that's not a duplicate. That's just another way to attempt to do what Windows is still not allowing me to do. That approach doesn't work, either, unfortunately. – Garret Wilson – 2018-10-19T23:23:00.983

(1) Is EmEditor still installed? Can you uninstall it and reboot to see if it now becomes easier to set the association? (2) In registry key HKEY_CLASSES_ROOT\.txt does the item (Default) have txtfile as value? (3) What is in key HKEY_CLASSES_ROOT\txtfile\shell\open\command the value of (Default) ? – harrymc – 2018-10-20T11:43:21.623

Let me take EmEditor out of the equation altogether. I just tried to associate a .tidyconfig file with VS Code. This extension has nothing associated with it at all. Even that didn't work. – Garret Wilson – 2018-10-20T15:11:46.877

That leaves my above questions (2) and (3). – harrymc – 2018-10-20T19:22:06.070

@harrymc I think you missed the point that if it can't even associate with .tidyconfig, then we don't even have to look at the HKEY_CLASSES_ROOT\.txt because now we are using HKEY_CLASSES_ROOT\.tidyconfig, which doesn't even exist. In other words, I have eliminated the whole issue of something incorrectly being configured in the registry for that extension. But to answer your questions, HKEY_CLASSES_ROOT\.txt for (Default) has emeditor64.txt, and HKEY_CLASSES_ROOT\txtfile\shell\open\command for (Default) has %SystemRoot%\system32\NOTEPAD.EXE %1. – Garret Wilson – 2018-10-21T00:17:23.253

HKEY_CLASSES_ROOT\.txt is already taken over by EmEditor. It would be interesting to know if you change it to txtfile and started EmEditor whether it would re-take it over. For the .tidyconfig problem, please give more information about what exactly you did to the registry. Check it against this article. – harrymc – 2018-10-21T10:05:21.890

I didn't do anything in the registry for .tidyconfig. I just tried to associate VS Code with the .tidyconfig extension as I would with any extension in Windows 10, as I explained in the description of this question. – Garret Wilson – 2018-10-21T14:39:04.060

Tell us exactly what you did for .tidyconfig. – harrymc – 2018-10-23T17:52:58.993

1

Possible duplicate of SSMS wont give up file associations

– Scott – 2018-11-11T17:42:58.037

Answers

3

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.

Dave the Sax

Posted 2018-10-17T16:37:33.550

Reputation: 186

At https://github.com/Microsoft/vscode/issues/61084 they also indicated the Windows bug and gave a link to https://www.reddit.com/r/windows/comments/9qeijs/cant_set_some_file_associations_properly_anyone/ 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 – 2018-11-01T00:05:23.460

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 – 2018-11-01T00:07:00.743

@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 – 2018-11-01T05:52:25.277

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 – 2018-11-01T14:36:01.860

@GarretWilson - Your bounty expired several days ago (as of Nov 1). So it’s likely you attempted to award it after it expired – Ramhound – 2018-11-05T02:41:20.893

Thanks for the edit. I'm aware of 61084 and the Reddit thread and read both in full before posting this workaround. Not everyone is happy with registry hacking but for those that are this will get around the problem for now (until MS break it again). Uninstalling KB4458469 could be another workaround but I didn't try that. – Dave the Sax – 2018-11-19T10:18:35.320

As of KB4471324 (the December 2018 update) I can now associate file types with VS Code. And someone else reported that the earlier KB4467682 actually fixed the problem, but I can't confirm that. In any case it seems this was indeed a Microsoft Windows, which has now been addressed with the latest updates.

– Garret Wilson – 2018-12-16T21:29:22.263

0

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

https://answers.microsoft.com/en-us/windows/forum/windows_10-other_settings/how-to-add-a-program-to-the-default-list-in/21c06a03-70db-43ff-9689-342e5ca4509f

enter image description here

enter image description here

Hawkeye Parker

Posted 2018-10-17T16:37:33.550

Reputation: 173

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 – 2019-01-24T21:46:01.277