Initial commit

This commit is contained in:
2014-05-01 09:40:29 -04:00
commit e154b00453
7 changed files with 425 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Microsoft.Tools.WindowsInstallerXml;
namespace WixFileVersionExtension
{
public class WixFileVersionPreprocessorExtension : PreprocessorExtension
{
private static readonly string[] prefixes = { "fileVersion" };
public override string[] Prefixes
{
get { return prefixes; }
}
public override string EvaluateFunction(string prefix, string function, string[] args)
{
switch (prefix)
{
case "fileVersion":
// Make sure there actually is a file name
if (args.Length == 0 || args[0].Length == 0)
throw new ArgumentException("File name not specified");
// Make sure the file exists
if (!File.Exists(args[0]))
throw new ArgumentException(string.Format("File name {0} does not exist", args[0]));
// Get the file version information for the given file
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(args[0]);
// Get the property that matches the name of the function
PropertyInfo propertyInfo = fileVersionInfo.GetType().GetProperty(function);
// Make sure the property exists
if (propertyInfo == null)
throw new ArgumentException(string.Format("Unable to find property {0} in FileVersionInfo", function));
// Return the value of the property as a string
return propertyInfo.GetValue(fileVersionInfo, null).ToString();
}
return null;
}
}
}