Issues using Resharper6 with Razor
I've just installed the latest and greatest from Resharper, namely version 6. The feature list of this includes support for Razor. However, I get some odd errors when using it for Razor. I have the following simple view in About.cshtml
using Razor:
@{
ViewBag.Title = "About";
}
<h2>About</h2>
When I start writing "ViewBag" R#6 helps me autocomplete this word, and when I put in the "." it tells me that "Title" is one of the properties available on the ViewBag-object. However, the ViewBag is underlined with a squiggly line, and the error is:
One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?
Both these dll's are present.. Note that this was a basic example, but I get the same error in every line of Razor code I ha开发者_JS百科ve.. Some places give a different error-msg though:
Module 'mscorlib', Version 4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' should be referenced.
Trying to add a reference to this in my project tells me:
A reference to 'mscorlib' could not be added. This component is already automatically referenced by the build system.
Anyone seen the same errors? How can I fix this and make the squiggly lines go away?
The problem is now figured out... It turned out that this was only a problem in our existing projects, and not a problem when starting new projects. In our existing projects we don't have a Web.Config
file. Instead we have several similarly named config files (Web.Dev.Config
, Web.Test.Config
, Web.Prod.Config
, etc), and we copy one of these into Web.Config
in our build process. This is a problem for Resharper. Resharper looks for some Razor-references in the projects Web.Config
file, and when it can't find those references it gets problems parsing your .cshtml-files.
So; be sure to have a Web.Config
file in the projects that require it if you want to use Resharper with Razor!
I had the same problem. Answer of stiank81 set me in right direction but I missed some example. I figured it out so here is an example web.config. So, if resharper says:
Module 'AssemblyName, Version=1.x.x.xxx, Culture=neutral, PublicKeyToken=null' should be referenced
then add this web.config to your project
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" >
<assemblies>
<add assembly="AssemblyName, Version=1.x.x.xxx, Culture=neutral, PublicKeyToken=null" />
</assemblies>
</compilation>
</system.web>
</configuration>
精彩评论