如何为Web应用程序创建exe?

时间:2013-02-07 10:19:28

标签: asp.net web-applications exe

我使用Visual Studio 2012(ASP.Net 4.5 - C#)开发了一个Web应用程序和一个Web服务。两者都在一个解决方案中。我需要将我的解决方案转换为EXE文件(为我的Web应用程序创建EXE)。我需要的是,如果运行我的安装文件,它应该在IIS中托管我的Web应用程序和Web服务。请提供解决问题的步骤。

2 个答案:

答案 0 :(得分:0)

也许您需要创建一个Web设置项目。 " Web设置项目提供 部署网站的最高灵活性。虽然Web Setup Projects更多 对于开发人员而言,它们允许您生成MSI包,预编译网站, 并执行您的应用程序可能需要的几乎任何设置任务。

许多网站不需要自定义配置。在这些情况下,您可以简单地构建 您的MSI文件并准备部署。但是,更复杂的方案包括依赖项 (例如特定的操作系统版本或服务包),自定义注册表项, 或管理员配置。 Web Setup Projects允许您部署满足的网站 这些要求。"

查看书籍" MCTS Self-Paced Training Kit(考试70-515) - 使用Microsoft .NET Framework 4进行Web应用程序开发"在第8章"调试和部署"。

希望这有帮助。

答案 1 :(得分:0)

安静回答: 我无法在此处发布整个项目,但是我会在此处发布流程图,您可以尝试一下。

此处流程图中的所有步骤均应以编程方式进行控制。

1。启动应用程序的步骤。

enter image description here

注意:如果您使用的是本地数据库(.mdf),请忽略第三层(已添加网站)

用于本地数据库的连接字符串:

public string ConnectionString =
            "Data Source=(local);Initial Catalog=YOUR_DATABASE_NAME;Integrated Security=True";

但是请记住,您需要安装dotnet框架才能运行您的应用程序。不必担心,因为您可以在应用程序设置项目中设置前提条件。

下面流程图中的所有代码。

是否已安装IIS

  

注意:我正在发布IIS 7及更高版本的代码。

public bool IsIISInstalled()
        {
            return Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp",
                "VersionString", null) != null;
        }

安装IIS

public int InstallIIS()
        {
            string DISM_CMD_CODE = "START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService /FeatureName:IIS-Metabase /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ODBCLogging /FeatureName:IIS-Performance /FeatureName:IIS-RequestFiltering /FeatureName:IIS-RequestMonitor /FeatureName:IIS-Security /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-StaticContent /FeatureName:IIS-URLAuthorization /FeatureName:IIS-WebDAV /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-WMICompatibility /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ProcessModel /FeatureName:WAS-WindowsActivationService";
            string command = DISM_CMD_CODE;
            ProcessStartInfo pStartInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
            Process p = new Process();
            p.StartInfo = pStartInfo;
            //p.WaitForExit();
            p.Start();
            return 1;
        }

是否添加了网站

public bool IsWebsiteAddedInIIS(string WebsiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == WebsiteName);
            if (site == null)
            {
                //No site added
                return false;
            }
            else
            {
                //site added
                return true;
            }
        }

public int CreateNewWebsite(string SiteName, string PublishedFilesPath)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site == null)
            {
                serverManager.Sites.Add(SiteName, "http", "*:8080:", PublishedFilesPath);
                serverManager.CommitChanges();
                return 1;
            }
            else
            {
                return 2;
            }
        }

public void StartWebsite(string SiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site != null)
            {
                site.Stop();
                site.Start();
            }
        }

        public void StopWebsite(string SiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site != null)
            {
                site.Stop();
            }
        }

获取网站URL

public string GetWebsiteURL(string SiteName)
        {
            //string SiteUrl = "";
            //ServerManager serverManager = new ServerManager();
            //var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            //var siteBindings = site.GetCollection("bindings");
            //string protocol = (string)siteBindings["protocol"];
            //string bindingInfo = (string)siteBindings["bindingInformation"];
            //if (protocol.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            //{
            //    string[] parts = bindingInfo.Split(':');
            //    if (parts.Length == 3)
            //    {
            //        //Get the port in use HERE !!!
            //        string port = parts[1];
            //        SiteUrl = "localhost:" + port;
            //    }
            //}
            //return SiteUrl;

            int port = 0;
            string SiteUrl = "";
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            foreach (Binding binding in site.Bindings)
            {
                port = binding.EndPoint.Port;
                SiteUrl = "localhost:" + port + "/index.aspx";
                break;
            }
            return SiteUrl;
        }

初始化浏览网站

  

您必须在Windows窗体上安装Cefsharp Chrome浏览器

安装软件包CefSharp.WinForms-版本75.1.143

public void InitBrowser(string Address)
        {
            Cef.Initialize(new CefSettings());
            browser = new ChromiumWebBrowser(Address);
            Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
        }

谢谢..