从MVC应用程序创建EXE

我使用MVC 3 Web应用程序创建了一个游戏应用程序,就像这样

在此处输入图像描述

控制器/动作就像是\ Home \ Game

我想知道是否可以将此MVC应用程序转换为EXE文件,因此,任何用户都可以在他的PC上运行它。 我知道我们可以为Windows应用程序创建EXE文件,Web App是否可能?

不是直接的。

你可以做的是使用mono xsp有一个简单的嵌入式web服务器,你可以将它放入.exe,然后在xy端口启动一个web服务器,打开一个带有的web浏览器

http://localhost:xy/optional-virtual-directory/Home/Game

您还需要将webserver-assembly本地复制到您的web-app的/ bin目录,以使其无需任何安装即可工作。

您还需要本地复制所有必需的ASP.NET MVC-3程序集(因为它们很可能默认情况下不会安装)。
并且你需要添加版本1.0.0,万一有人在本地安装了MVC-4。

即便如此,它还需要在目标计算机上安装.NET framework 4.0(或至少3.5?)。

这里是最新的stable-XSP源的链接:
http://download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2

您可以将压缩的Web应用程序包含为嵌入式资源,并使用解压缩库将其解压缩到可写目录,您可以将其设置为Web服务器的根目录。

确保你的unzip-library正确解压缩JavaScript文件,因为微软提供的windows-server windows-explorer-integrated-zip-handling实用程序无法正确解压缩它们(可能取决于服务器版本和安全设置/策略)。

 static void Main() { int iPort = 8080; // If admin rights it requires, wrong it is ;) iPort = 30080; // Damn ! I still no haz no admin rightz ! string strBasePath = @"D:\UserName\documents\visual studio 2010\Projects\EmbeddableWebServer\TestApplication"; string strCurrentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(strCurrentDirectory); //strBasePath = System.IO.Path.Combine(di.Parent.Parent.Parent.FullName, "TestApplication"); strBasePath = System.IO.Path.Combine(di.Parent.Parent.Parent.FullName, "TestMvcApplication"); //EmbeddableWebServer.cWebSource WebSource = new EmbeddableWebServer.cWebSource(System.Net.IPAddress.Any, iPort); Mono.WebServer.XSPWebSource ws = new Mono.WebServer.XSPWebSource(System.Net.IPAddress.Any, iPort); // EmbeddableWebServer.cServer Server = new EmbeddableWebServer.cServer(WebSource, strBasePath); Mono.WebServer.ApplicationServer Server = new Mono.WebServer.ApplicationServer(ws, strBasePath); Server.AddApplication("localhost", iPort, "/", strBasePath); Server.Start(true); System.Diagnostics.Process.Start("\"http://localhost:" + iPort.ToString() + "\""); Console.WriteLine(" --- Server up and running. Press any key to quit --- "); Console.ReadKey(); Server.Stop(); } // End Sub Main 

我使用此代码来解决丢失的语言环境处理问题。

 using System; using System.Collections.Generic; using System.Text; namespace System { public class Locale { // http://msdn.microsoft.com/en-us/library/441722ys(v=vs.80).aspx // #pragma warning disable 414, 3021 public static string GetText(string message) { return message; } public static string GetText(string format, params object[] args) { return string.Format(format, args); } /* public static object GetResource(string name) { return name; } */ } // End Class Locale } // End Namespace System