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;
            }
        }
    }


相關文章
相關標籤/搜索