2017-01-16 87 views
1

我想要的是得到是在主輸出keyoutput性質的版本,它從myapp.msi重命名爲MYAPP-v1.0.15.45.msi如何查詢msi主輸出以獲取程序集版本?

enter image description here

在-VS-安裝項目-output-filename 我知道如何通過使用我在此link中找到的代碼來查詢msi,這裏是代碼。我怎麼能想要我想要使用類似的代碼片段?

static string GetMsiProperty(string msiFile, string property) 
    { 
     string retVal = string.Empty; 

     // Create an Installer instance 
     Type classType = Type.GetTypeFromProgID("WindowsInstaller.Installer"); 
     Object installerObj = Activator.CreateInstance(classType); 
     Installer installer = installerObj as Installer; 

     // Open the msi file for reading 
     // 0 - Read, 1 - Read/Write 
     Database database = installer.OpenDatabase(msiFile, 0); 

     // Fetch the requested property 
     string sql = String.Format("SELECT Value FROM Property WHERE Property='{0}'", property); 
     View view = database.OpenView(sql); 
     view.Execute(null); 

     // Read in the fetched record 
     Record record = view.Fetch(); 

     while (record != null) 
     { 
      Console.WriteLine(record.get_StringData(0) + '=' + record.get_StringData(1) + '=' + record.get_StringData(2) + '=' + record.get_StringData(3)); 
      record = view.Fetch(); 
     } 
     view.Close(); 
     System.Runtime.InteropServices.Marshal.FinalReleaseComObject(view); 
     System.Runtime.InteropServices.Marshal.FinalReleaseComObject(database); 

     return retVal; 
    } 

回答

0

目前尚不清楚你已經嘗試什麼,如果你運行該代碼在所有,但最簡單的回答是,你調用代碼,並索要的ProductVersion屬性。

ProductVersion property

相關問題