Web包未配置在Azure包中

时间:2013-11-03 14:51:11

标签: c# asp.net-mvc-4 azure assembly-binding-redirect

我正在尝试使用SDK工具2.2版在Azure中运行现有的可用Web应用程序。 Web应用程序作为“普通”MVC 4站点运行良好,并且在本地Azure模拟器中运行良好。该应用程序旨在运行在服务器上或作为Web角色运行。

我一直在尝试将它发布到Azure,但总是得到

Server Error in '/' Application

消息。通过启用远程桌面,我可以查看事件日志,这是我收到的消息。

(在此之后,但是对于tl; dr目的,我认为绑定重定向没有被提取,因为主要的抱怨是无法加载System.Web.Mvc 3.0.0.0。)

Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 11/3/2013 10:36:10 AM 
Event time (UTC): 11/3/2013 10:36:10 AM 
Event ID: 2be088053f02484e95f3f17fcd95b67e 
Event sequence: 1 
Event occurrence: 1 
Event detail code: 0 

Application information: 
Application domain: /LM/W3SVC/1273337584/ROOT-1-130279485699443947 
Trust level: Full 
Application Virtual Path: / 
Application Path: F:\sitesroot\0\ 
Machine name: RD00155D463D30 

Process information: 
Process ID: 1536 
Process name: w3wp.exe 
Account name: NT AUTHORITY\NETWORK SERVICE 

Exception information: 
Exception type: InvalidOperationException 
Exception message: The pre-application start initialization method Initialize on type    Elmah.Mvc.Bootstrap threw an exception with the following error message: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040).
at System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures)
at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at Elmah.Mvc.Bootstrap.Initialize()

Request information: 
Request URL: http://blizzard-propressroom.cloudapp.net/ 
Request path: / 
User host address: 176.27.246.0 
User:  
Is authenticated: False 
Authentication Type:  
Thread account name: NT AUTHORITY\NETWORK SERVICE 

Thread information: 
Thread ID: 5 
Thread account name: NT AUTHORITY\NETWORK SERVICE 
Is impersonating: False 
Stack trace:    at System.Web.Compilation.BuildManager.InvokePreStartInitMethodsCore(ICollection`1 methods, Func`1 setHostingEnvironmentCultures)
at System.Web.Compilation.BuildManager.InvokePreStartInitMethods(ICollection`1 methods)
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

我尝试卸载ELMAH以防万一,但我仍然无法加载MVC版本3.0.0.0。

现在当然这是有道理的,因为我正在运行MVC 4,这就是我在我的包中所拥有的。

当然,在本地运行v4不是问题,因为我的Web.config有:

<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
</dependentAssembly>

但显然Azure WebRoles不能使用Web.config(当然,如果我通过远程桌面找到源,那里的Web.config文件几乎是空的。)

我已经看到了一些建议,我需要一个app.config,我已经尝试过(只是web.config的直接副本),而Copy设置为Copy Always。我可以在我的bin文件夹中看到它的副本。

这对我来说似乎是一个非常令人困惑的箍,但似乎在Azure上绑定重定向的规则随着每个SDK版本而变化,因此在线存在大量冲突的信息。

所以在经过一个非常冗长的帖子之后:请有人知道我需要做些什么来告诉Azure有关绑定重定向的信息吗?(你是否同意这实际上是问题?)

更新

感谢@viperguynaz提供了一些建议,但要确认我的System.Web.MVC被标记为copy true。今天早上我尝试完全删除我的Azure项目,并在Visual Studio中使用转换为Windows Azure云服务项目选项,以防最初出现任何问题。但我仍然遇到同样的问题。

在Azure服务上使用远程桌面,我去了E:\ sitesroot \ 0。 Web.config几乎是空的。只是:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <machineKey decryption="AES" decryptionKey="F7FA540B4DFD82E5BB196B95D15FF81F6FC418E967F01A1C60FB407A84615031" validation="SHA1" validationKey="6FC418E967F01A1C60FB407A84615031902C0D9A9DE62168764FF0DCE537184F0535D5D9AD66DEDC6FC418E967F01A1C60FB407A84615031902C0D9A97DC1ABF" />
    </system.web>
</configuration>

没有我的web.config的迹象。但其他所有内容都是正确的,包括Views文件夹中的Web.config。

我的最新版本和发布在构建过程中告诉我一些非常有趣的内容:

warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.Razor.dll
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Razor.dll.
warning WAT153: The web project 'xxx' is dependent on the following MVC assembly: C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies\System.Web.WebPages.Deployment.dll.

对于所有这些:

MVC assemblies must be added to the package or installed on the virtual machine for your web role. For more details about this, see the following help page: http://go.microsoft.com/fwlink/?LinkId=218227.

现在看来很明显,除了之外,它们都被设置为与项目一起复制,我的项目被设置为Web角色(如链接所示)。有关于必须使用ASP Net MVC安装创建启动文件夹以及添加WebStart cs的链接,但我觉得这是过时的建议,否则为什么不能“转换为Windows Azure云服务项目” “做这些工作吗?

更新2

好吧,看起来我的Web.config文件由于某种原因没有被打包。我挖出了一个我在Azure中成功安装的项目,以7-zip打开了包文件,发现有一个捆绑的Web.config文件。此问题项目中没有此类web.config文件。我将开始尝试找出原因。

我还更新了问题标题以反映此信息。这几乎可以肯定是一切的原因。

3 个答案:

答案 0 :(得分:2)

原来这与Azure ASP.NET MVC Web.Config Deployment Issue

的情况相同

我的web.config的部署值为“none”(某种程度上)因此未包含在包中,这意味着创建了几乎为空的默认值。

我将部署类型更改为“内容”(使用Web.config上的“属性”),现在它已被捆绑。

答案 1 :(得分:0)

我认为您在RDP会话中找不到正确的web.config。站点(Web应用程序)存储在虚拟硬盘驱动器上,通常为e:\ sitesroot \ 0或f:\ sitesroot \ 0 - 您可以通过打开IIS并检查站点物理目录来确认。在该目录中,您将找到在构建/打包过程中转换的web.config。这是您的站点使用的web.config。通过在<customErrors mode="Off"/>部分添加<system.web>开始您的问题排查。然后从IIS本地浏览该站点。我怀疑你没有将System.Web.Mvc设置为Copy Local = True。接下来,您的web.config构建设置应为:

  • 构建操作=内容
  • 复制到输出目录=不复制(您不希望bin目录中有web.config文件)。

作为Azure部署的一般经验法则,如果应用程序使用的程序集的路径不在..\Reference Assemblies\..中,那么您很可能需要设置Copy Local = True以包含装配在bin目录中。

答案 2 :(得分:0)

确保在您的.csproj文件中包含了该文件,否则它将被忽略

<ItemGroup>
    ...
    <Content Include="App_Data\XMLDocument.xml" />
    <Content Include="Areas\HelpPage\HelpPage.css" />
    <Content Include="Areas\HelpPage\Views\Web.config" />   <----- THIS LINE
    <Content Include="Areas\HelpPage\Views\Help\Api.cshtml" />
    <Content Include="Areas\HelpPage\Views\Help\DisplayTemplates\ApiGroup.cshtml" />
    ...
</ItemGroup>

(由于建议编辑队列已满而添加)