从MVC应用程序创建EXE [英] Create EXE from MVC Application

查看:115
本文介绍了从MVC应用程序创建EXE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have created a Game Application using MVC 3 Web Application which is like this

此操作的控制器/动作就像\ Home \ Game

the controller/action for this is Like \Home\Game

我想知道是否可以将此MVC应用程序转换为EXE文件,以便任何用户都可以在其PC上运行它.我知道我们可以为Windows应用程序创建EXE文件,Web应用程序可以吗?

I want to know is it possible to convert this MVC app into an EXE file so, any user can run it on his PC. I know we can create EXE file for windows app, is it possible for Web App?

推荐答案

不直接.

您可以做的是使用mono xsp拥有一个简单的嵌入式Web服务器,您可以将其放入.exe,然后将在端口xy上启动Web服务器,并使用

What you can do is use mono xsp to have a simple embedded webserver, which you can put into a .exe, which will then start a webserver on port xy, and open a web-browser with with

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

您还需要将该Webserver-assembly本地复制到您的Web应用程序的/bin目录中,以使其无需安装即可工作.

you also need to localcopy that webserver-assembly to your web-app's /bin directory for it to work without any installation.

您还需要对所有必需的ASP.NET MVC-3程序集进行本地复制(因为它们很可能在默认情况下未安装).
而且,如果有人在本地安装了MVC-4,则需要添加1.0.0版.

You'll also need to localcopy all necessary ASP.NET MVC-3 assemblies (because they are most-likely not installed by default).
And you need to add version 1.0.0 just in case somebody has installed MVC-4 locally.

即使如此,它仍然需要在目标计算机上安装.NET Framework 4.0(或至少3.5吗?).

And even then, it requires .NET framework 4.0 (or at least 3.5?) installed on the target computer.

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

Here a link to the latest stable-XSP sources:
http://download.mono-project.com/sources/xsp/xsp-2.10.2.tar.bz2

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

You can include the zipped web application as embedded resource and use a unzip-library to unzip it to a writeable directory, which you set as your webserver's root directory.

请确保您的解压缩库确实正确解压缩了JavaScript文件,因为Microsoft提供的Windows-server windows-explorer-integrated-zip-handling实用工具无法正确解压缩它们(可能取决于服务器版本和安全设置/策略)

Make sure your unzip-library does properly unpack JavaScript files, because the microsoft-supplied windows-server windows-explorer-integrated-zip-handling utility does not properly unpack them (may depend on server version and security settings/policy).

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 

我使用此代码来解决缺少的语言环境处理问题.

I used this code to get around the missing locale-handling.

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


2019更新:

从2019年底开始,您可以使用.NET Core 3.1,这样您就可以构建一个独立的应用程序,用户可以在不安装.NET框架的情况下运行该应用程序.

As per end-2019, you can use .NET Core 3.1, that way you can build a self-contained application, which the user can run without having .NET framework installed at all.

要针对x86和x64构建独立的.NET Core应用程序,请执行以下操作:

To build a self-contained .NET Core Application for x86 and x64:

dotnet restore -r win-x86
dotnet build -r win-x86
dotnet publish -f netcoreapp3.1 -c Release -r win-x86

Kestrel是一个集成的Web服务器,您可以使用它代替Mono.XSP.
这样,您可以在端口xy(其中xy是未使用的端口号)上运行MVC/.NET核心Web应用程序,并在http(s)://localhost:xy

Kestrel is an integrated web-server which you can use instead of Mono.XSP.
With that, you can run your MVC/.NET-Core Web-Application on port xy (where xy is an unused port-number), and start a web-browser on http(s)://localhost:xy

这篇关于从MVC应用程序创建EXE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆