[Source: http://geekswithblogs.net/EltonStoneman]

One of the frustrations of working with WiX is that when you want to do something out of the ordinary, chances are it’s provided somewhere in a WiX extension, but unless you trawl through the XSDs you’re not likely to find it. I had this issue when I wanted to resolve the special folder My Music through WiX, so I could put the full path into a config file.

Various special folders are already available as properties to the installer, including My Documents and My Pictures, but not My Music. Adding an extension to expose Environment.GetSpecialFolder() to WiX is a trivial implementation in a couple of classes (comments omitted for brevity):

public class EnvironmentExtension : WiXExtension

{

private EnvironmentPreprocessorExtension preprocessorExtension;

public override PreprocessorExtension PreprocessorExtension

{

get

{

if (this.preprocessorExtension == null)

{

this.preprocessorExtension = new EnvironmentPreprocessorExtension();

}

return this.preprocessorExtension;

}

}

}

public class EnvironmentPreprocessorExtension : PreprocessorExtension

{

private const string SPECIALFOLDER = “specialFolder”;

public override string[] Prefixes { get { return new string[] { SPECIALFOLDER }; } }

private List<string> _specialFolders;

private List<string> SpecialFolders

{

get

{

if (_specialFolders == null)

{

_specialFolders = new List<string>(Enum.GetNames(typeof(Environment.SpecialFolder)));

}

return _specialFolders;

}

}

public override string GetVariableValue(string prefix, string name)

{

string result = null;

if (prefix == SPECIALFOLDER && SpecialFolders.Contains(name))

{

Environment.SpecialFolder specialFolder = (Environment.SpecialFolder)Enum.Parse(typeof(Environment.SpecialFolder), name, true);

result = Environment.GetFolderPath(specialFolder);

}

return result;

}

}

Reference the folder you want from the Environment.SpecialFolders enum as a property in your WiX script:

<Property Id=MUSICPATH Value=$(specialFolder.MyMusic)/>

– and add the extension assembly to your light and candle calls, making sure the DLL is available at runtime :

candle -out x.y.z.WiXobj x.y.z.wxs -ext EnvironmentExtension

light -out x.y.z.msi x.y.z.WiXobj -ext EnvironmentExtension -cultures:en-us

But I suspect it’s already available somewhere in WiX.