How does Visual Studio choose which editor to use for a file? - visual-studio

My project stores html code fragments for use in templating in files with a custom extension (*.phtml). I find that Visual Studio is inconsistent in its use of editors when I edit these files. Sometimes it provides no intellisense, sometimes it treats the files as XML (which is better than nothing), and sometimes I get lucky and it provides me with the HTML editor.
I've configured Visual Studio to treat *.phtml files as HTML, but that doesn't seem to make any difference.
What more can I do to convince Visual Studio to always use the HTML Editor for *.phtml files?

Right-clicking a file in solution explorer shows an "Open with ..." option, the window that it opens has a choice of editors plus a "Set as default" option.

Related

Visual Studio 2017 "Script Editor" rejects files with extensions other than '.vbs'

Problem: I want to edit VBScript files from inside Visual Studio 2017, but the files have the extension '.mts' instead of '.vbs'
Theory: See helpful article here.
Steps Tried: I performed a few Registry hacks in order to get 'Script Editor' to show up as a choice in the 'Open With' menu. However, even now that 'Script Editor' is the default for MTS files, I don't get syntax highlighting when opening them. The linked article suggest that 'Script Editor' is 'rejecting' the document, causing Visual Studio to default to the base text editor, but I don't see a reason why this should be happening.
A couple of options:
Set Visual Studio Options: Tools => Options => Text Editor => File Extension. Add mts extension and set editor to Microsoft Visual Basic - that should do I think.
VbsEdit: Another alternative could be to use a VBScript tool such as VbsEdit. I tested it and it seems to apply syntax coloring even for files that do not end in *.vbs. This is a commercial tool, but is great for VBScripts. It features its own debugger and also an extensive samples library in the Samples menu (not affiliated).

Visual Studio: Defining File Type Regardless of File Extension

Where to define, what kind of type a particular file within Visual Studio solution is?
I have observed that file extensions do not necessarily have to relate to the actual file types within VS.(observed within Visual Studio 2010, 2012).
For example: I have an existing Visual Studio solution. In another tool, I have created an HTML file with .html extension. After importing it into Visual Studio solution, the file does not gain HTML Intellisense and Code Completion.
On the other hand, I can create an HTML file within Visual Studio through: Visual Studio -> FILE -> New File -> HTML Page
This file will gain all its HTML related Code Highlight, Intellisense, and Code Completion features. I can then rename its extension to, say, .txt. The file will still keep its HTML properties such as code highlight, intellisense, etc..
My question therefore is, where can I define/change, what kind of file type (HTML, CSS, JavaScript) the particular file is, regardless of its extension? This is important, to be able to assign appropriate Intellisense, Code Highlight, Code Completion features.

How to associate .scss files with CSS intellisense in VS2010

I'd like to be able to use IntelliSense in .scss files for speed, but I can't see a way of associating the file type.
I've tried using Mindscape Web Workbench, and found the functionality didn't meet my needs.
After a bit of research I found that you could build file extension associations in Tools>Options>Text editor>File extension, but none of the options in the Editor DDL seemed applicable for CSS.
In Visual Studio 2012, you can do the following:
Go to Tools > Options > Text editor > File Extension
Enter scss in the Extension box.
Select CSS Source Editor from the Editor box.
For Visual Studio 2010, CSS Source Editor doesn't appear to be an option. This extension appears to do what you ask for: ScssInCss.

Can Visual Studio 2010 do ".inc" file syntax highlighting?

Can Visual Studio 2010 be configured to do syntax highlighting on ".inc" files? We have numerous large projects with tons of these ".inc" files (asp files) and so changing the file extension to ".asp" is not an option. All I want Visual Studio 2010 to do is treat these ".inc" files just like ".asp" files when it comes to syntax highlighting.
I've tried "Open With..." and selected the HTML Editor, which is the ".asp" default, but that did not work. I tried about every other editor in the list and none of them worked.
I know Notepad++ (among others) can do this, but I would prefer this be done in Visual Studio 2010 - using another IDE or text editor is not the answer I'm looking for here.
In Visual Studio...go to Options -> Text Editor -> File Extension. Type in 'inc' as extension and editor as 'Web Form Editor'. You may need to close then re-open your currently open .Inc pages...Hope this helps
I found both the 'Web Form Editor' and 'HTML Editor' to be less than ideal for me. Both of them appeared to highlight the syntax of the HTML ok, but the VBScript keywords were left in standard black text along with everything else.
While not ideal, I followed the instructions from the other answers, but substitude Visual Basic as the editor type and that worked much more to my liking (as they were include files, there is little HTML in them).
Options -> Text Editor -> File
Extension. Type in 'inc' as extension and set editor as 'Visual Basic'.
Close and re-open any '.inc' files and highlighting should be visible.
Antonio's solution worked for me. I did have to close and reopen files, but after I re-opened them the highlighting was visible. Thanks!
Options -> Text Editor -> File Extension.
Type in 'inc' as extension and set editor as 'Web Form Editor'.
Close and re-open any '.inc' files and highlighting should be visible.
Incidentally, this also works in Visual Studio 2005.
Use the File Extension, Text Editor, Options Dialog Box.
http://msdn.microsoft.com/en-us/library/4k7w5e5s.aspx
-update-
I see the same behavior :-( Will let you know if I find anything.
As a workaround, could you rename all your .inc files to .asp?
This has the added advantage that if a request is made for the inc file directly (highly unlikely but possible; and assuming you have the incs in the web directory), your code will be exposed unlike .asp where it is processed and rendered.
I really wanted to add a comment, because this is not a direct answer, but apparently you need 50 reputation for that.
I've found that in Visual Studio 2005 (again, in Tools -> Options -> Text Editor -> File Extension), both "Web Form Editor" and "User Control Editor" highlight both the HTML and the VBScript.
Amadiere mentioned that "Web Form Editor" doesn't highlight the VBScript in 2010, but maybe it's worth trying "User Control Editor", if that's an option in 2010.
In Visual Studio 2010 and 2012 Express it best works for me when I use "Microsoft Visual Basic" with my .inc files. Nevertheless, it's still not the same as with .asp files as there's no Autocomplete nor IntelliSense (Ctrl+Space, Ctrl+Shift+Space etc.) with the .inc files.
It should be made possible defining that .inc files are to be treated just as .asp files.
I agree with Purple Coder:
You should not name the files containing ASP code as .inc. It is a security risk. Anyone who knows/can guess the filename can open it in a browser and view the actual code inside the file.
But, first of all in my case this is an intranet page and therefore not very risky, as most people there would somehow find the files on the server anyway. I'm also not sure where this naming convention came from. It was there before I started. This was started on Visual Studio 6.
But, to avoid this risk there's a simple solution: add .inc in the Application Mapping of the IIS in the same manner as .asp.
You should not name the files containing ASP code as .inc. It is a security risk. Anyone who knows/can guess the filename can open it in a browser and view the actual code inside the file.

Using the Visual Studio XML Editor on RDL files

When using Visual Studio to edit Reporting Services *.rdl files, the default designer used is from the "Microsoft SQL Server Reporting Services Designers" installed product.
When viewing the RDL code, this code is displayed as plain text and I want to take advantage of the XML Editor in visual studio.
Linking the *.rdl extension to the XML editor in Tools>Options>Text Editor>File Extension has the nasty side effect that while the rdl is now shown in the XML editor, the original report designer completely disappears.
Is there some other way to do this?
thanks
For any file you can click the arrow on the size of the open button in the open file dialog and select open with... From there you can select the XML editor. There are some other useful open with items in there as well.
You should be able to view and modify the XML by doing a view source on the RDL file. That way you'll still be able to use the designer when needed.
It would seem that the Report Designer for Visual Studio 2005 did not provide XML Editor support when you click "View Source"; where the 2008 version does.
While "solved", this is just a little inconvenient when you still need to develop RDL in 2005 compatibility mode.

Resources