开发者

How to develop a simple ASP.NET MVC project without Visual Studio

开发者 https://www.devze.com 2023-03-21 22:43 出处:网络
I have been able to develop a simple asp.net project without vs. Can some开发者_如何学Cone help me doing the same for a asp.net mvc 3. Starting from getting the ASP.NET MVC 3 framework. It seems that

I have been able to develop a simple asp.net project without vs. Can some开发者_如何学Cone help me doing the same for a asp.net mvc 3. Starting from getting the ASP.NET MVC 3 framework. It seems that we can't download anymore the assemblies. Is it possible to have the project compiled on the fly ( I mean without compiling the my web application but letting IIS doing so , it is possible to achieve this with the regular asp.net so I assume it could be possible with the MVC framework)

Thx Dave


Sure, it's pretty easy, only a couple of steps after you install ASP.NET MVC 3.

  1. Fire notepad.exe and create a HomeController.cs file (Of course if you don't want to use notepad you could also do this by using the copy con HomeController.cs command on the command prompt, this way you will be closer to the metal):

    namespace MyApplication
    {
        using System.Web.Mvc;
    
        public class HomeController : Controller
        {
            public ActionResult Index()
            {
                return View();
            }
        }
    }
    
  2. Compile on the command prompt (adjust the folders to match yours)

    c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /t:library /out:MyApplication.dll /r:"C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll" HomeController.cs
    
  3. Create a folder c:\MyApplication

  4. Create a folder c:\MyApplication\bin and copy MyApplication.dll to this bin folder.
  5. Inside c:\MyApplication\web.config:

    <?xml version="1.0"?>
    <configuration>
      <appSettings>
        <add key="webpages:Version" value="1.0.0.0"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
      </appSettings>
    
      <system.web>
        <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=1.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=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>
    
        <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>
      </system.web>
    
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>
    
    </configuration>
    
  6. Inside c:\MyApplication\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=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
          <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=1.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=3.0.0.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.web>
        <httpHandlers>
          <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
    
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <controls>
            <add assembly="System.Web.Mvc, Version=3.0.0.0, 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>
    
  7. Inside c:\MyApplication\Global.asax:

    <%@ Application Language="C#" %>
    <%@ Import Namespace="System.Web.Mvc" %>
    <%@ Import Namespace="System.Web.Routing" %>
    <script runat="server">
    
    static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
    
    void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
    </script>
    
  8. Inside c:\MyApplication\Views\Home\Index.cshtml:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    
    <body>
        Hello Word
    </body>
    </html>
    
  9. Now you have all the necessary files for an ASP.NET MVC 3 application. The final step is to host it on a web server and run it.


Conclusion: unless you are suffering from some severe brain damage you will never do this and simply download Visual Studio 2010 Express and start developping ASP.NET MVC 3 applications by following the tutorials on the ASP.NET MVC web site.


Could you give a reason you don't want to use visual studio? There are free versions that are quite capable as IDEs.

If you would prefer to learn in a much more text editor experience you can also use Microsoft WebMatrix to create them on your local computer.

The easiest way to install Webmatrix or Visual Studio Web Developer Express is probably using the Web Platform Installer.

0

精彩评论

暂无评论...
验证码 换一张
取 消