我试图将我的旧项目从3.0.0.0升级到4.0.0.1,它给我100多个错误
例如。 当前上下文中不存在名称“模型” “ViewBag”这个名称在当前的上下文中不存在 当前上下文中不存在名称“T” 等等
继承我的web.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=152368
-->
<configuration>
<configSections>
<section name="routeMapping" type="flubes.Configuration.Routing.RouteMappingConfiguration, flubes" requirePermission="false" />
<section name="site" type="flubes.Configuration.SiteConfiguration, flubes" requirePermission="false" />
<section name="redirector" type="flubes.Configuration.Redirector.RedirectorConfiguration, flubes" requirePermission="false" />
<section name="integration" type="flubes.Configuration.Integration.IntegrationConfiguration, flubes" requirePermission="false" />
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" requirePermission="false" />
</configSections>
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
<routeMapping configSource="Config\Routes.config" />
<site configSource="Config\Site.config" />
<redirector configSource="Config\Redirector.config" />
<integration configSource="Config\Integration.config" />
<nlog configSource="Config\Logging.config" />
<connectionStrings>
<add name="Forums" connectionString="Data Source=ADAM\MSSQLSERVER2;Initial Catalog=forums;User ID=sa;Password=xxxx;Integrated Security=TRuE;" />
<add name="Membership" connectionString="Data Source=ADAM\MSSQLSERVER2;Initial Catalog=forums;User ID=sa;Password=xxxx;Integrated Security=TRUE;" />
<!-- <add name="YourDb" connectionString="Data Source=localhost;Initial Catalog=AdventureWorksLT2008;User ID=sa;Password=12345678" providerName="System.Data.SqlClient" />
The above connectionstring with name "forums" will be used by the site.
Below this line you can see 2 samples of connection strings, one that points to a Microsoft SQL Server database and other that points to a MySql database.
<add name="ForumsMSSQL" connectionString="Data Source=localhost;Initial Catalog=Forums;User ID=sa;Password=12345678" providerName="System.Data.SqlClient"/>
<add name="ForumsMySql" connectionString="Server=localhost;Database=forums;Uid=user;Pwd=12345678;" providerName="MySql.Data.MySqlClient"/>
-->
</connectionStrings>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add invariant="MySql.Data.MySqlClient" name="MySQL Data Provider" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
<!--
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory" from="admin@yoursite.com">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
</smtp>
</mailSettings>
</system.net>
-->
<system.web>
<authentication mode="Forms" />
<membership defaultProvider="ForumsMembershipProvider">
<providers>
<clear />
<add name="ForumsMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="Membership" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="30" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="flubes" />
<!--
<add name="ForumsMembershipProvider"
type="MySql.Web.Security.MySQLMembershipProvider, MySql.Web, Version=6.3.6.0, Culture=neutral"
connectionStringName="Forums"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" passwordFormat="Hashed" maxInvalidPasswordAttempts="30" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" passwordStrengthRegularExpression="" applicationName="flubes"/>
-->
</providers>
</membership>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.Helpers, Version=2.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.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Web.WebPages, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<customErrors mode="Off" />
<pages>
<namespaces>
<add namespace="System.Web.Helpers" />
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="System.Web.WebPages" />
</namespaces>
</pages>
<trust level="Full" />
<httpHandlers>
<remove verb="GET,HEAD,POST" path="*" />
<add verb="*" path="*" type="flubes.Web.Handlers.StaticFileHandler, flubes.Web" />
</httpHandlers>
<httpModules>
<add name="RedirectorModule" type="flubes.Web.Modules.RedirectorModule, flubes.Web" />
<add name="ModelBinderModule" type="flubes.Web.Modules.ModelBinderModule, flubes.Web" />
<add name="CompressionModule" type="flubes.Web.Modules.CompressionModule, flubes.Web" />
</httpModules>
<httpRuntime requestValidationMode="2.0" />
</system.web>
<!--
IIS 7.0. or above
-->
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<modules runAllManagedModulesForAllRequests="true">
<add name="RedirectorModule" type="flubes.Web.Modules.RedirectorModule, flubes.Web" />
<add name="ModelBinderModule" type="flubes.Web.Modules.ModelBinderModule, flubes.Web" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
继承人观点/ 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=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=2.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=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="flubes.Web.UI.BaseViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="flubes"/>
<add namespace="flubes.Dto"/>
<add namespace="flubes.Validation"/>
<add namespace="flubes.Configuration"/>
<add namespace="flubes.Web.Extensions"/>
<add namespace="System.Security"/>
<add namespace="System.Collections"/>
</namespaces>
</pages>
</system.web.webPages.razor>
<appSettings>
<add key="webpages:Enabled" value="false" />
</appSettings>
<system.web>
<httpHandlers>
<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
</httpHandlers>
<!--
Enabling request validation in view pages would cause validation to occur
after the input has already been processed by the controller. By default
MVC performs request validation before a controller processes the input.
To change this behavior apply the ValidateInputAttribute to a
controller or action.
-->
<pages
validateRequest="false"
pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<controls>
<add assembly="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
</controls>
</pages>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<remove name="BlockViewHandler"/>
<add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>
</system.webServer>
</configuration>
答案 0 :(得分:0)
Visual Studio非常适合管理大多数任务的项目,但升级依赖项是经常出错的地方。通常,您需要通过直接编辑.csproj
文件来进行手动干预。
首先,保存解决方案中要保存的所有工作。然后在解决方案资源管理器中右键单击您的MVC项目,然后单击&#34;卸载项目&#34;。这将只为项目留下一个节点,然后是(unavailable)
。右键单击该节点,然后选择Edit XXX.csproj
,其中XXX是您的项目名称。在弹出的任何对话框上单击“确定”。这将打开.csproj
文件的XML视图(实际上是MSBuild文件)。向下滚动文件,查找对System.Web.Mvc
,System.Web.Razor
和System.Web.WebPages.Razor
的引用是否正确,确保没有重复的Reference
条目 。如果配置正确,它应如下所示。
<Reference Include="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Mvc.4.0.20710.0\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.Razor.4.0.20715.0\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<Private>True</Private>
<HintPath>..\packages\Microsoft.AspNet.WebPages.4.0.20710.0\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
请注意,上面的示例适用于.NET framework 4.0。要定位另一个框架版本,您应该将\net40\
段更改为packages文件夹中最接近的版本。此外,您应始终检查以确保在HintPath
。
完成后,保存文件,然后在解决方案资源管理器中右键单击项目节点,然后单击Reload Project
。
如果您的项目具有引用MVC的依赖项目,则应对所有项目重复相同的过程。
如果您的项目具有引用MVC的依赖DLL,请首先尝试获取引用MVC的正确版本的版本。如果不存在,则使用binding redirects确保所有从属DLL使用相同的MVC版本。
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
注意:如果您正在使用MVC的其他功能,则可能会有更多引用和绑定重定向更新,而不是上面列出的内容。找出所需版本的最简单方法是创建一个新的MVC 4项目,将相同的引用(新版本)添加到新项目中,然后分析
.csproj
和web.config文件以引入正确配置您要升级的项目。
当然,您还需要在涉及版本的任何地方检查并升级web.config文件中的引用,但您显然已经完成了该步骤。