aspnet_compiler 发现 System.Web.WebPages 1.0.0.0 而不是 2.0.0.0 的错误版本 [英] aspnet_compiler finding wrong version of System.Web.WebPages 1.0.0.0 instead of 2.0.0.0

查看:20
本文介绍了aspnet_compiler 发现 System.Web.WebPages 1.0.0.0 而不是 2.0.0.0 的错误版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET MVC4 项目,它在 VS2010 中编译得很好.出于部署目的,我运行了一个 Nant 脚本,该脚本尝试使用 aspnet_compiler.exe 预编译网站,但我一直遇到 System.Web.WebPage 的程序集引用问题

I have an ASP.NET MVC4 project which compiles fine in VS2010. For deployment purposes I run a Nant script which attempts to precompile the website using aspnet_compiler.exe but I keep running into an assembly reference issue with System.Web.WebPage

错误 CS1705:程序集System.Web.Mvc,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35"使用System.Web.WebPages,版本=2.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad"它的版本高于引用的程序集 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

error CS1705: Assembly 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' uses 'System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

我的 web.config 中还有以下程序集绑定:

I also have the following assembly bindings in my web.config:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
        <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

我的 csproj 有以下参考:

and my csproj has the following reference:

<Reference Include="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
  <Private>True</Private>
 <HintPath>..packagesAspNetWebPages.Core.2.0.20126.16343lib
et40System.Web.WebPages.dll</HintPath>
</Reference>

推荐答案

我通过在 Web.config 中显式引用 2.0 程序集解决了这个问题.我想出于某种原因,ASP.NET 编译器(在我的情况下,在运行 MvcBuildViews 时)首先使用旧的 1.0 程序集(如果找到).

I solved this problem by explicitly referencing the 2.0 assembly in Web.config. I suppose that for some reason, the ASP.NET compiler (in my case when running MvcBuildViews), uses the old 1.0 assembly first, if it is found.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!-- … -->
  <system.web>
    <!-- … -->
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
        <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
      </assemblies>
    </compilation>
    <!-- … -->
  </system.web>
  <!-- … -->
</configuration>

顺便说一句:看起来这个问题是在我添加 3rd 方 ASP.NET MVC 3.0 组件后第一次出现的.该组件通过程序集绑定工作正常,但这可能是 ASP.NET 编译器尝试首先加载 1.0 网页的原因.

BTW: It looked like this problem occurred for the first time after I added a 3rd party ASP.NET MVC 3.0 component. That component works fine through the assembly binding, but it may be the reason why the ASP.NET compiler tries to load the 1.0 web pages first.

这篇关于aspnet_compiler 发现 System.Web.WebPages 1.0.0.0 而不是 2.0.0.0 的错误版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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