How does VS determine which version of Razor engine to use when editing razor webpage files

Xinyang Qiu

In VS2013 Preview, we released new Razor V3 runtime and design time Engine to support MVC5 and Razor V3 website’s runtime and design time behavior. Unlike Razor V2 runtime and design time, VS2013 did not GAC these binaries. Instead, the binaries are installed in the project bin folder when corresponding NuGet package is installed, and in “%ProgramFiles (x86)%\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\Web\Razor\v3.0” to support design time.

As in VS2012 to determine which razor v1/v2 design time dlls to load, VS 2013 preview first use web.config file key <add key=webpages:Versionvalue=x.0.0.0/> to determine the design time dll version to load for editing webpages. For example, by default, MVC5 project contains <add key=webpages:Versionvalue=3.0.0.0/> , VS will load Razor V3 dlls to edit the project’s webpage files (i.e. cshtml or vbhtml files) .

If the key is missing from web.config file such as default Razor V2/V3 website, VS will use bin directory’s razor dll version to determine the design time razor engine dll to load.

Since Razor v1 is no longer ships with VS2013 preview, if a single webpage file (i.e. cshtml or vbhtml files) is opened without bin directory nor web.config setting, VS 2013 preview will simply load the webpage as a plain text file.  Updated 10/9/2013: In VS2013 RC and RTW, VS will open the single webpage file using the highest Razor version on the box.

You can verify these behavior by debugging into the Visual Studio process and check the module window, filter with razor keyword.

 

0 comments

Discussion is closed.

Feedback usabilla icon