如何在VS Setup Project输出文件名中包含版本号 [英] How to include version number in VS Setup Project output filename

查看:470
本文介绍了如何在VS Setup Project输出文件名中包含版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在VS2008安装项目中将版本号作为output.msi文件名的一部分包含在内?

Is there a way to include the version number as part of the output.msi filename in a VS2008 Setup Project?

例如,我想要一个输出文件:"myinstaller-1.0.13.msi",其中根据我在部署项目属性中输入的版本号自动设置版本部分.

I'd like for example an output file called: "myinstaller-1.0.13.msi" where the version part is automatically set based on the version number I have put in the deployment project properties.

推荐答案

不知道您是否仍然需要这样做,但还是想回答这个问题,因为我们在postbuild事件中进行了类似的操作.据我所做的研究,这不可能通过设置过程在内部设置所需的文件名.

Not sure whether you still require this or not but wanted answer this as we did similar kind of operation in the postbuild event. As far as the research I did this is not possible to set the file name as you want internally through setup process.

您可以通过其他方法通过在构建后事件中通过外部应用程序命名输出文件来实现.

You can do this in other way by naming the output file through an external application in post build event.

这是您可以做的:

在构建后事件中->

[MsiRenamerAppPath] \ MsiRenamer.exe"$(BuildOutputPath)"

[MsiRenamerAppPath]\MsiRenamer.exe "$(BuildOutputPath)"

创建一个应用程序,该应用程序将使用部署项目中的版本号重命名msi文件.以下是用于该应用程序的代码.我猜这应该满足您的要求.

Create an application which will rename the msi file with the version number from the deployment project. Following is the code used for the application. This should fulfill your requirement I guess.

替代文章

class MsiRenamer
  {
    static void Main(string[] args)
    {
      string inputFile;
      string productName = "[ProductName]";

      if (args.Length == 0)
      {
        Console.WriteLine("Enter MSI file:");
        inputFile = Console.ReadLine();
      }
      else
      {
        inputFile = args[0];
      }

      try
      {
        string version;

        if (inputFile.EndsWith(".msi", StringComparison.OrdinalIgnoreCase))
        {
          // Read the MSI property
          version = GetMsiProperty(inputFile, "ProductVersion");
          productName = GetMsiProperty(inputFile, "ProductName");
        }
        else
        {
          return;
        }
        // Edit: MarkLakata: .msi extension is added back to filename
        File.Copy(inputFile, string.Format("{0} {1}.msi", productName, version));
        File.Delete(inputFile);
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
      }
    }

    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();
      if (record != null)
      {
        retVal = record.get_StringData(1);
        System.Runtime.InteropServices.Marshal.FinalReleaseComObject(record);
      }
      view.Close();
      System.Runtime.InteropServices.Marshal.FinalReleaseComObject(view);
      System.Runtime.InteropServices.Marshal.FinalReleaseComObject(database);

      return retVal;
    }
  }

这篇关于如何在VS Setup Project输出文件名中包含版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆