zoukankan      html  css  js  c++  java
  • 项目安装包制作

    以前没有动手做过安装包,所以第一次做还是费了不少劲,最近在网上也查看了很多资料,这里也想总结一下。

    (1)新建安装项目setup1,填写名称和位置:

    (2)在解决方案中右键点击项目选择“视图->文件系统”:

    (3)选择应用程序文件夹,右键“添加->文件”,添加安装所需要的可执行文件、图片、dll文件等。

    (4)在应用程序文件夹的文件安装属性里设置安装目录DefaultLocation,也可以用默认的。

    (5)点击exe文件创建快捷方式,分别粘贴至用户的“程序”菜单和用户桌面,这样安装后就会出现在开始程序菜单里和桌面上,建议在用户的程序菜单下建一个文件夹,

    将快捷方式放在文件夹中,可以修改快捷方式的属性,为快捷方式添加图标和修改显示的名称,这里就简单写写了。

    (6)最后生成解决方案,一个简单的安装包就做好了。

    注:当然一个完整的安装包光这点是远远不够的,本人也在学习当中,比如: 1 卸载:可以在应用程序文件夹中添加msiexec.exe文件,创建快捷方式,更改此快捷方式的Arguments 为"/x {产品id}",产品id的值

    为打包項目的ProductCode属性值. 也可以添加一个安装程序,通过程序来实现卸载功能;2 自动添加数据库:新建一个类库,添加一个安装程序,在安装程序中重写Install(IDictionary stateSaver),修改配置

    文件,添加数据库操作;3 根据需要添加用户界面、用户自定义操作等,剩下的这里就不罗列了。实现一个功能方法有很多种,关键要看自己需要的是什么,什么样的方法适合自己的项目。这里有一篇讲的很详细,

    http://www.cnblogs.com/aaa6818162/archive/2009/08/06/1540489.html。下面是是一段数据库自动

    附加的代码:

    namespace ClassLibrary1
    {
        [RunInstaller(true)]
        public partial class Installer1 : Installer
        {
            public Installer1()
            {
                InitializeComponent();
            }
    
            public override void Install(IDictionary stateSaver)
            {
                base.Install(stateSaver);
    
                //修改配置信息
                System.IO.FileInfo fileInfo = new FileInfo(this.Context.Parameters["targetdir"] + "\\DbConfig.xml");
                if (!fileInfo.Exists)
                {
                    throw new InstallException("没有找到配置信息!");
                }
                try
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(fileInfo.FullName);
                    foreach (XmlNode node in xmlDocument.ChildNodes)
                    {
                        if (node.Name == "SystemProperty")
                        {
                            node.Attributes.GetNamedItem("ConnectionString").Value = string.Format("server={0};User ID={1};Password={2};Initial Catalog = database_bak; Integrated security = true", this.Context.Parameters["server"], this.Context.Parameters["user"], this.Context.Parameters["pwd"]);
                        }
                    }
                    xmlDocument.Save(fileInfo.FullName);
                    //xmlDocument.Save(this.Context.Parameters["targetdir"] + "DbConfig.xml");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString() + "数据库配置修改失败!");
                }
    
                //附加数据库
                try
                {
                    SqlConnection myCon = new System.Data.SqlClient.SqlConnection(string.Format("server=LOCALHOST\\SQLEXPRESS;User ID={0};Password={1};Integrated security = true", this.Context.Parameters["user"], this.Context.Parameters["pwd"]));
                    myCon.Open();
                    SqlCommand myCom = new SqlCommand();
                    myCom.Connection = myCon;
                    myCom.CommandText = string.Format("Create Database database on (filename ='{0}\\database.mdf'),(filename = '{0}\\database_log.ldf') for attach", this.Context.Parameters["targetdir"]);
                    myCom.ExecuteNonQuery();
                    myCon.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString() + "数据库操作失败!");
                }
            }
        }
    }
    
  • 相关阅读:
    Lighthead SiteCrawler
    svnbook
    SFTP in Python: Really Simple SSH
    WP Robot Wordpress plugin logo
    use curl to post data for work punch
    Setting up Hudson on port 80 on a Debian or Ubuntu machine
    Problem with PEXPECT in Python
    H2 Database Engine — h2database.com — Readability
    execnet: rapid multiPython deployment
    Maven问题总结 3 技术改变生活商业成就梦想 51CTO技术博客
  • 原文地址:https://www.cnblogs.com/zelmeli/p/2054412.html
Copyright © 2011-2022 走看看