Setup Project 安装项目

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

在新建Setup Project

Setup Project 安装项目
 

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

Setup Project 安装项目
 

File System中,可以选择程序安装的目录。

Setup Project 安装项目

Setup Project 安装项目
注意一点,Setup Project本身不提供卸载的功能。需要自己添加。
可以在Application Folder添加Uninstall.bat文件,内容是:
C:\Windows\system32\MsiExec.exe /I{ProduceCode}
ProduceCode需替换成Setup Project属性中的ProduceCode
 
还可以在User' Programs Menu中添加指向Uninstall.bat的快捷链接
Setup Project 安装项目
 
这里提到可以调用系统自带的 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

Setup Project 安装项目
 
在这里可以增加自定义的安装界面,但是只能用它定义好的样式,不能内嵌页面
Setup Project 安装项目
 

增加Custom Action

Setup Project 安装项目
 
这里可以添加自定义的,针对安装期间生命周期的事件。我这里是在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;
            }
        }
    }

上一篇:一则spring容器启动死锁问题(DefaultListableBeanFactory/DefaultSingletonBeanRegistry)


下一篇:NGINX的启停命令、以及动态加载配置文件的命令