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

控制器/动作就像\ Home \ Game
我想知道是否可以将此MVC应用程序转换为EXE文件,以便任何用户都可以在其PC上运行它。我知道我们可以为Windows App创建EXE文件,Web App是否可以?
不直接。
您可以做的是使用mono xsp拥有一个简单的嵌入式Web服务器,您可以将其放入.exe,然后将在端口xy上启动Web服务器,并使用以下命令打开Web浏览器:
http://localhost:xy/optional-virtual-directory/Home/Game
您还需要将该Web服务器程序集本地复制到Web应用程序的/ bin目录中,以使其无需安装即可工作。
您还需要对所有必需的ASP.NET MVC-3程序集进行本地复制(因为默认情况下最有可能未安装它们)。
而且,如果有人在本地安装了MVC-4,则需要添加1.0.0版。
即使这样,它仍需要在目标计算机上安装.NET Framework 4.0(或至少3.5?)。
这里是最新的稳定XSP源的链接:http :
//download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2
您可以将压缩的Web应用程序作为嵌入式资源包括在内,并使用解压缩库将其解压缩到可写目录,并将其设置为Web服务器的根目录。
确保您的解压缩库确实正确解压缩了JavaScript文件,因为Microsoft提供的Windows-server 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
Run Code Online (Sandbox Code Playgroud)
我使用此代码来解决缺少的语言环境处理问题。
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
Run Code Online (Sandbox Code Playgroud)
2019更新:
从2019年底开始,您可以使用.NET Core 3.1,这样就可以构建独立的应用程序,用户可以在不安装.NET框架的情况下运行该应用程序。
要为x86和x64构建独立的.NET Core应用程序,请执行以下操作:
dotnet restore -r win-x86
dotnet build -r win-x86
dotnet publish -f netcoreapp3.1 -c Release -r win-x86
Run Code Online (Sandbox Code Playgroud)
Kestrel是一个集成的Web服务器,您可以使用它代替Mono.XSP。
这样,您可以在端口xy(其中xy是未使用的端口号)上运行MVC / .NET-Core Web应用程序,并在以下位置启动Web浏览器:http(s)://localhost:xy
| 归档时间: |
|
| 查看次数: |
3378 次 |
| 最近记录: |