47

I'm playing around with MVC 5 RC 1 in Visual Studio 2013 RC. Works very well.

Now I upgraded an existing MVC 4 project in VS 2012 to MVC 5 the same way as described here

I also changed the web.config(s) - see "upgrading from MVC4 to MVC5"

Everything (build, run web app, even intellisense) works perfectly except the syntax highlighting of Razor/C# code in views.

I also tried it with an MVC 5 project created in VS 2013. Same result. So I assume VS 2012 doesn't "understand" the new assemblies?!

Any known workaround or ideas to get highlighting back?

Community
  • 1
  • 1
Andreas
  • 2,252
  • 1
  • 19
  • 29

7 Answers7

75

Microsoft released a new version of ASP.NET Web Tools for VS 2012. After installing syntax highlighting is back again.

http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx

Installing VS 2012 Update 4 was not enough.

A set of offline installers is available. The offline installers are easier to use than the Web Platform Tools invoker (WebNode11Pack.exe @ ~114KB):

If you want an offline installer then please goto http://www.microsoft.com/en-us/download/details.aspx?id=41532

  • AspNetWebTools2013_1Setup.exe @ ~39MB
  • WebToolsExtensionsVS.msi (for Visual Studio 2012 standard edition[s]) @ ~21MB
  • WebToolsExtensionsVWD.msi (for Visual Studio 2012 free "Web" edition[s]) @ ~21MB
starlocke
  • 3,407
  • 2
  • 25
  • 38
Andreas
  • 2,252
  • 1
  • 19
  • 29
  • 1
    This isn't fixing it for me. I have installed the new version of Web Tools but Razor syntax is still not working. Any ideas? – Simon Hartcher Oct 30 '14 at 02:42
  • 1
    Same as Simon Hartcher here. I have installed all the tools and checked the web.config files, still to no luck. – Fadi Chamieh Nov 05 '14 at 08:45
  • Can you provide more details on your setup? – Andreas Nov 05 '14 at 09:36
  • This has the syntax somewhat working for me, but everything is underlined in red. For example, even ViewBag is underlined and says, "The name 'ViewBag' does not exist in the current context." – Delford Chaffin Nov 06 '15 at 19:26
16

ASP.NET and Web Tools 2013.1 for Visual Studio 2012 has now been released and should resolved the MVC5 intellisense issue with VS 2012.

This release brings a ton of great improvements, and include some fantastic enhancements to ASP.NET MVC 5, Web API 2, Scaffolding and Entity Framework to users of Visual Studio 2012 and Visual Studio 2012 Express for Web.

You can download the update: http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx

To Moderator: It might be just a download link, but this resolve the issue, it worked for me and it worked for the users that voted this as answer. If you are going to delete it please provide a reason, thanks!

Adam Lear
  • 38,111
  • 12
  • 81
  • 101
hatsrumandcode
  • 1,871
  • 2
  • 19
  • 21
  • 1
    You're absolutely right. I was also a little bit confused why your answer was suddenly gone. That's the reason I provided the link as an answer by myself. But the credits are yours! – Andreas Nov 19 '13 at 13:24
  • Thanks @Andreas lets hope it does not get deleted again :) – hatsrumandcode Nov 19 '13 at 14:00
9

This answer claims that VS2012 can't understand Razor 3, so you (and me) will have to upgrade to VS2013

Community
  • 1
  • 1
flipchart
  • 6,548
  • 4
  • 28
  • 53
  • Downvoters, please add a comment. My answer was valid when posed, but since then MS has added support for VS 2012 so it is now a little outdated. However, I don't see a need to update it to effectively the same text as posted by C Style – flipchart Jul 10 '14 at 10:27
6

I am currently using a workaround to get the IntelliSense working in VS2012 (I assume that this would not work properly a) if I was using VS2013 for the same project; b) if I tried using Razor 3 features):

Change the web.config to use old webpages version:

<add key="webpages:Version" value="2.0.0.0" />

To make sure that this does not impact the production in any way I added a web.config transformation:

<add key="webpages:Version" value="3.0.0.0" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" />

Unfortunately this workaround has issues (that I have noticed so far):

  • Extension methods (like Html.RenderPartial() are not recognized and show up as error in the designer).
Knaģis
  • 20,827
  • 7
  • 66
  • 80
  • thats a neat workaround - did you encountered any side effects yet? – Andreas Oct 22 '13 at 12:53
  • @Andreas - nothing so far but it has yet to roll out to other developers so if I catch anything I will make sure to add them to this answer. – Knaģis Oct 22 '13 at 13:09
  • first drawback that I noticed (don't know how it skipped past me the first time) added to the answer... makes the workaround rather useless but since I'm sticking with MVC5 for now, it is still better than nothing. – Knaģis Oct 22 '13 at 13:50
6

I got this answer from Microsoft developer:

MVC 5/Razor 3 tooling support for VS 2012 has not shipped yet. We hope to ship this support in Mid November.

So the accepted answer is true for now but we can plan to soon have this support in VS2012 as well.

Knaģis
  • 20,827
  • 7
  • 66
  • 80
  • 10
    I installed VS2012 Update 4 today and it hasn't fixed it. – cirrus Nov 14 '13 at 17:01
  • I sent an e-mail to Microsoft, they said that the support is still in works and has not been shipped. Unfortunately they did not say anything more specific :( – Knaģis Nov 18 '13 at 11:00
  • I'm using VS2013 instead now. The appear to have gotten the round-tripping between VS2012 and VS2013 working this time and all my addins are working OK or better. No teething issues with using VS2013 vs VS2012 discovered yet so I'm staying. No reason to use VS2012 anymore. – cirrus Nov 18 '13 at 14:43
  • 1
    @cirrus You have to install additionally http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx – Andreas Nov 19 '13 at 09:32
3

install the "ASP.NET and WebTools 2013.1 for Visual Studio 2012" in the Microsoft Platform Installer

chsword
  • 2,032
  • 17
  • 24
1

For me, my issue was that I had my build files being output to a directory other than bin. Once my files we're output to bin, then my syntax highlighting came back.

One way to fix this is to create a post-build action which copies the files in the project-rooted bin folder (vs a filter outside of the project) to your target directory.

The following article explains: http://www.dennisonpro.info/managing-intellisense-in-razor-views-with-mvc-5-using-custom-builds-in-visual-studio-2013/

Ryan Griffith
  • 1,591
  • 17
  • 41