Setup Project 安装项目

从vs2012起,微软已经不支持setup project了。以此记念一下setup project。
 

在新建Setup Project

 

增长安装内容,一般是直接Oupput一个项目,或者直接添加exe,dll

 

File System中,能够选择程序安装的目录。

注意一点,Setup Project自己不提供卸载的功能。须要本身添加。
能够在Application Folder添加Uninstall.bat文件,内容是:
C:\Windows\system32\MsiExec.exe /I{ProduceCode}
ProduceCode需替换成Setup Project属性中的ProduceCode
 
还能够在User' Programs Menu中添加指向Uninstall.bat的快捷连接
 
这里提到能够调用系统自带的 msiexec.ext 进行卸载。可是经网友测试得出以下结论:
Awesome, works very well for me on WinXP/Vista & Win7. Worth noting that according to the article linked to, if you use a version of msiexec.exe HIGHER than the target platform there are issues. This is not an issue for me as I'm still intentionally using XP for building - but obviously if you want an installer built on Vista to run on XP that will be an issue.  
 
也有网友提出以下解决方案
Regarding the problem that arises when building the Installer under Vista/7, and the installer tries to overwrite msiexec on older, XP machines; this can be corrected by creating an empty .txt file, and renaming it to "msiexec.exe." Include that file in your installer, rather than the  actual  System32 version. Since the empty, fake file has no version information, it will not try to overwrite the XP msiexec
 
但我试过,是行不通的。>_<
 
因此,仍是乖乖用回Uninstall.bat实现卸载。
 

增长User Interface

 
在这里能够增长自定义的安装界面,可是只能用它定义好的样式,不能内嵌页面
 

增长Custom Action

 
这里能够添加自定义的,针对安装期间生命周期的事件。我这里是在dll中定义了一个InstallHelper的类,在安装的过程当中写一个xml文件
    [RunInstaller( true )]
      public class InstallHelper : Installer
    {
          public override void Install(System.Collections.IDictionary stateSaver)
        {
              base .Install(stateSaver);
 
              try
            {
 
                  string brandType = string .IsNullOrEmpty(Context.Parameters[ "BrandType" ]) ? "HuaShi" : Context.Parameters[ "BrandType" ];
              
                  string assemblypath = Context.Parameters[ "assemblypath" ];
 
                  string pathName = Path.Combine(Path.GetDirectoryName(assemblypath), brandType + ".xml" );
 
                  if (File.Exists(pathName))
                {
                    File.Delete(pathName);
                }
 
                  using (Stream st = File.Open(pathName, FileMode.OpenOrCreate))
                {
                    var writer = XmlWriter.Create(st);
                    writer.WriteStartDocument();
 
                    writer.WriteStartElement( "Info" );
                    writer.WriteElementString( "Seed" , System.Guid.NewGuid().ToString());
                    writer.WriteElementString( "Brand" , brandType);
                    writer.WriteEndElement();
                    writer.Close();
                }
            }
              catch (FormatException e)
            {
                  string s = e.Message;
            }
        }
    }


相关文章
相关标签/搜索