VS2015 - 智能感知没有剃刀视图工作在类库 [英] VS2015 - IntelliSense not working in razor views in a class library

查看:354
本文介绍了VS2015 - 智能感知没有剃刀视图工作在类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有描述确切的问题很难,但似乎是公正的智能感知的问题,只显示剃刀(.cshtml)的意见。一直在寻找这2天,所以我现在真的可​​以使用一些帮助。

I am having a hard time describing the exact issue, but is appears to be "just" an IntelliSense problem that only shows in razor (.cshtml) views. Been looking at this for 2 days now so I could really use some help.

我使用VS2015专业版,开始使用标准模板一个新的Web MVC应用程序(WebApplication2)。里面的那个应用程序的一切工作就好了。

I am using VS2015 Pro, started a new Web MVC application (WebApplication2 ) using the standard template. Inside that application everything works just fine.

现在我添加了一个类库项目(默认的,而不是包模板),并添加了网页,MVC和剃须刀的NuGet包到它(在相关情况)。这个问题,只要我在类中创建库一个新的观点变得可见。看来,到系统库中的所有引用是CSHTML文件不可用。
在没有打开的文件我没有错误可言,但是当我打开视图中的所有系统类下面有红色的波浪线,和错误列表(建设+智能感知)突然包含了很多错误的每个系统*库,例如

Now I have added a class library project (the default one, not the "Package" template), and added the WebPages, MVC and razor nuget packages to it (in case that is relevant). The problem becomes visible as soon as I create a new view in the class library. It appears that all references to System libraries are unavailable in the cshtml file. With no files opened I get no errors at all, but when I open the view all system classes have the red squiggly line under them, and the Error list (Build + IntelliSense) suddenly contains a lot of errors for every system* library, example:

The type or namespace name 'Mvc' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)

这包括LINQ的,和WebApplication2(测试项目),所以不只是System.Web程序。

These include Linq, and the WebApplication2 (the test project), so not just System.Web.

这是我已经确认并做了类似的答案基础上堆的东西:

Things that I have checked and done bases on similar answers on stack:


  • 在浏览文件夹中的web.config文件中包含了正确的版本,还试图仅仅复制从Web应用程序之一。

  • 重新安装的NuGet包(MVC,剃须刀,网页)。

  • 重置用户数据并删除文件夹.VS。

  • 复制本地设置为true的组件。

在这里我们发现这是我们这是在VS2010工作的罚款较大的Web应用程序,但后来我们决定升级到2015年和.NET 4.6的实际情况。类库中的观点被标记为嵌入的资源,并使用虚拟路径提供加载。上面的例子是一个超级简单的重复性的项目,症状是在我和我的同事们2的计算机一样。

The actual case where we discovered this is our larger web application which was working fine in VS2010, but then we decided to upgrade to 2015 and .Net 4.6. The views in the class library are marked as embedded resource and loaded using a virtual path provider. The case above is a super simplified reproducible project, the symptoms are the same on my and my 2 colleagues' computers.

如果我错过了信息的决定性位,请只问。

If I missed a crucial bit of information, please just ask.

图像可视化问题

推荐答案

文章斯蒂芬Muecke与评论让我在正确的方向开始的答复。该解决方案可能是我的困惑的组合,其中配置必须是在哪里,什么感觉像一个解决方法的东西...

A reply in the article Stephen Muecke commented with got me started in the right direction. The solution is a mix of probably my confusion of which config needs to be where, and what feels like a workaround to something...


  1. 设置你的类库项目的[输出路径]到[斌/]。穆罕默德Chehab提到这对他(目前离线?)博客这是本文中引用后:的http://thetoeb.de/2014/01/05/enabling-mvc5-intellisense-in-a-classlibrary-project/

在您的[ClassLibrary /浏览次数]文件夹,你应该有一个Web.config文件,其中包括正确的剃刀版本以及命名空间。我刚刚从我们的工作Web应用程序项目复制的Web.config的内容,并添加/更改一些命名空间。下面的例子。

In your [ClassLibrary/Views] folder you should have a Web.config which includes the correct razor versions and namespaces. I just copied the contents of the Web.config from our working Web application project and added/changed some namespaces. Example below.

在您的[ClassLibrary]根文件夹,你应该改变App.config中,使其还包含编译设置system.web节。下面的例子。

In your [ClassLibrary] root folder you should change the App.config so that it also contains the system.web section with the compilation setting. Example below.

改变这些到一个干净后,关闭解决方案,删除文件夹仓,打开解决方案,对我来说最后都再次合作。
我确实有System.Web.Mvc.xml零星的问题被锁定,或许输出路径更改,MS没有预见或东西...也许没有什么可担心的副作用。

After changing these to a clean, close the solution, delete the bin folders, open the solution and for me it finally all worked again. I do have a sporadic issue with System.Web.Mvc.xml being locked, perhaps a side effect of the output path change that MS did not foresee or something... Perhaps nothing to worry about.

希望这有助于一些谷歌上搜索可怜的灵魂有一天。

Hope this helps some poor googling soul some day.

项目/查看/ Web.config中

Project/Views/Web.config

<?xml version="1.0"?>

<configuration>
  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.Mvc.WebViewPage">
      <namespaces>
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization"/>
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <appSettings>
    <add key="webpages:Enabled" value="false" />
  </appSettings>

  <system.webServer>
    <handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
    </handlers>
  </system.webServer>

  <system.web>
    <compilation>
      <assemblies>
        <add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      </assemblies>
    </compilation>
  </system.web>
</configuration>

项目/ App.config中

Project/App.config

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=301880
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.6" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-7.0.0.0" newVersion="7.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>ConfigureAuth
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

这篇关于VS2015 - 智能感知没有剃刀视图工作在类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆