Which NuGet package creates the web.config in your

2019-05-19 06:30发布

My project is missing the web.config file from the Views folder. Here are the steps I took to make the project.

  • Created an empty MVC project and installed the packages listed below.
  • Created a controller and view. The view was created by right-clicking the action name and selecting 'Add View...' from the menu.
  • Attempt to run the project, but got the error CS0103: The name 'ViewBag' does not exist in the current context

I am getting this error because web.config is missing from my Views folder. Since the web.config contains a lot of version numbers, tokens, etc..., my question is:

  1. Why wasn't this added when I installed the packages?
  2. Did the packages create a template I can use to make the web.config file?

Packages I installed:

Antlr   3.4.1.9004
bootstrap   3.3.4
jQuery  1.9.1
Microsoft.AspNet.Mvc    5.2.3
Microsoft.AspNet.Razor  3.2.3
Microsoft.AspNet.Web.Optimi...  1.1.3
Microsoft.AspNet.WebPages   3.2.3
Microsoft.Web.Infrastructure    1.0.0.0
Modernizr   2.6.2
Newtonsoft.Json 5.0.4
Ninject 3.2.2.0
Ninject.MVC5    3.2.1.0
Ninject.Web.Common  3.2.0.0
Ninject.Web.Common.WebHost  3.2.0.0
WebActivatorEx  2
WebGrease   1.5.2

1条回答
Emotional °昔
2楼-- · 2019-05-19 06:36

Should prob look like this, as said in the comments it's part of the project template and not a package

<?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.2.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.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>
</configuration>

UPDATE

The above is the default config file from the Views folder, it is added to a new Web Project when it's created using Visual Studio 2013. It uses

  • Microsoft.AspNet.Mvc 5.2.2
  • Microsoft.AspNet.Razor 3.2.2
  • Microsoft.AspNet.WebPages 3.2.2
查看更多
登录 后发表回答