如何为我的 C# 应用程序制作安装程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2251062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:46:36  来源:igfitidea点击:

How to make an installer for my C# application?

c#winformsinstaller

提问by Moon

I have created an application (C#, Windows Forms) on Visual Studio 2008, and now I want to make installer of this application. How can this be done?

我在Visual Studio 2008上创建了一个应用程序(C#Windows 窗体),现在我想制作这个应用程序的安装程序。如何才能做到这一点?

I want my installer to

我希望我的安装程序

  • Copy all the files that my application is using to a user chosen path (copy the files to the chosen, some for the server-side application and some for the client side).
  • Also install .NET3.5
  • Check for SQL Serveror SQL Server Express Edition
  • 将我的应用程序正在使用的所有文件复制到用户选择的路径(将文件复制到所选路径,一些用于服务器端应用程序,一些用于客户端)。
  • 同时安装.NET3.5
  • 检查SQL ServerSQL Server Express Edition

How can I do it?

我该怎么做?

采纳答案by sashaeve

  1. Add a new install project to your solution.
  2. Add targets from all projects you want to be installed.
  3. Configure pre-requirements and choose "Check for .NET 3.5 and SQL Express" option. Choose the location from where missing components must be installed.
  4. Configure your installer settings - company name, version, copyright, etc.
  5. Build and go!
  1. 向您的解决方案添加一个新的安装项目。
  2. 从要安装的所有项目中添加目标。
  3. 配置先决条件并选择“检查 .NET 3.5 和 SQL Express”选项。选择必须安装缺失组件的位置。
  4. 配置您的安装程序设置 - 公司名称、版本、版权等。
  5. 建造并开始!

回答by Anton Gogolev

Generally speaking, it's recommended to use MSI-based installations on Windows. Thus, if you're ready to invest a fair bit of time, WiXis the way to go.

一般来说,建议在 Windows 上使用基于 MSI 的安装。因此,如果您准备投入相当多的时间,WiX是您的最佳选择。

If you want something which is much more simpler, go with InnoSetup.

如果您想要更简单的东西,请使用InnoSetup

回答by Asad

There are several methods, two of which are as follows. Provide a custom installer or a setup project.

有几种方法,其中两种如下。提供自定义安装程序或安装项目。

Here is how to create a custom installer

这是创建自定义安装程序的方法

[RunInstaller(true)]
public class MyInstaller : Installer
{
    public HelloInstaller()
        : base()
    {
    }

    public override void Commit(IDictionary mySavedState)
    {
        base.Commit(mySavedState);
        System.IO.File.CreateText("Commit.txt");
    }

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        System.IO.File.CreateText("Install.txt");
    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);
        File.Delete("Commit.txt");
        File.Delete("Install.txt");
    }

    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
        File.Delete("Install.txt");
    }
}

To add a setup project

添加设置项目

  • Menu file-> New-> Project--> Other Projects Types--> Setup and Deployment

  • Set properties of the project, using the properties window

  • 菜单文件->新建->项目-->其他项目类型-->设置和部署

  • 使用属性窗口设置项目的属性

The article How to create a Setup package by using Visual Studio .NETprovides the details.

文章如何使用 Visual Studio .NET 创建安装程序包提供了详细信息。

回答by Diansheng

Why invent wheels yourself while there is a car ready for you? I just find this tools super easy and intuitive to use: Advanced Installer. This one minute videoshould be enough to impress you. Here is the illustrative user guide.

为什么要在有车的时候自己发明轮子呢?我只是发现这个工具使用起来非常简单和直观:高级安装程序。这个一分钟的视频应该足以让你印象深刻。这是说明性的用户指南