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

8

17

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.

Agripinaagrippa answered 27/5, 2010 at 16:6 Comment(1)
Did you find a solution to this, which work reliably ? It seems to do odd this, like not work with big inc files then later in the day it works file. Also tried the registry key trick.Carlenecarleton
P
17

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

Propraetor answered 28/7, 2010 at 16:48 Comment(0)
S
11

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.
Stalinsk answered 10/2, 2011 at 13:40 Comment(0)
M
4

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.

Misstep answered 25/11, 2010 at 5:24 Comment(1)
This worked for me. Unfortunately, it looks like Visual Studio doesn't give you as much flexibility as would be ideal .. for example, I wanted to edit cs.pp files as C#, and cshtml.pp files as Web Form, but it doesn't consider cs.pp or cshtml.pp to be valid extensions. I just had to use pp and pick one or the other :-(Cottle
M
2

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.

Massingill answered 27/5, 2010 at 16:11 Comment(1)
I appreciate the quick response Raj, however, this solution doesn't work like I wanted. When I put in ".inc" and have it open with the HTML Editor, which is the ".asp" file default, it will highlight the code delimiters and html, but nothing between the code delimiters is highlighted - keywords (Dim, If, Then, Else, etc), strings, etc. I know it seems like it should work, but if you test it for yourself you'll see it does not syntax highlight exactly like asp files - it's like the HTML Editor is hardcoded to treat asp files differently.Agripinaagrippa
P
1

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.

Pepsinate answered 16/1, 2013 at 11:36 Comment(0)
E
0

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.

Embrangle answered 30/1, 2013 at 8:52 Comment(0)
E
0

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.

Embrangle answered 30/1, 2013 at 19:19 Comment(0)
E
-2

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.

Epsom answered 30/1, 2013 at 8:59 Comment(5)
You can tell your server to not publicly serve any file type you like, so that's not really true.Hatty
@jblasco: Give me one good reason for relying server configuration (and tweaking it) when you can simply use .asp extension.Epsom
For the benefit of semantically indicating that the file is not meant to be a publicly accessible ASP page, but an include file. You can also then fully block access to .inc files, whereas if it kept the .asp extension, would it not still be served up if hit directly at its URL?Hatty
It is possible to name a file that semantically make sense while keeping .asp extension. I code in PHP too, other people too, I never used or saw someone using *.inc to indicate an include file.Epsom
True, but then users can still guess the filename and open the .asp page directly... I just don't really see the benefit of using .asp if your server is capable of parsing .inc as ASP and doesn't serve it publicly.Hatty

© 2022 - 2024 — McMap. All rights reserved.