Geeks With Blogs

News This is the *old* blog. The new one is at blog.sixeyed.com

Elton Stoneman
This is the *old* blog. The new one is at blog.sixeyed.com

[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.

Posted on Tuesday, September 29, 2009 1:09 PM Code Snippet , Wix | Back to top


Comments on this post: Resolving Special Folders in WiX 3.0

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
These are nice coding. These code helps a lot. Keep sharing such type of informative post.
Left by dormire a lucca on May 31, 2010 5:00 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
New tool, Heat, that generates .wxs source files based on a file, directory, or website along with improved COM object registration capture are some of good point in wix 3.0
Left by firewall network security on Oct 26, 2010 4:39 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
This is an updated release of WiX v3. It is recommended that we use WiX v2 for our personal product development.
Left by taxi privato Fiumicino on Nov 22, 2010 9:27 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
great info just what was needed
Left by celebrity news today on May 13, 2011 11:58 PM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
Thanx for the post, when our group gets bigger, we will come back to see if you have any more interesting follow up topics to link to from your new blog site ;-) Indian London escorts
Left by London Escorts on Jun 05, 2011 12:34 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
Quite possibly the most succinct and current info I came across about this subject. Sure pleased that I discovered that site by accident. I’ll probably be subscribing for your feed so that I will get the most current updates. Like the information here.
Left by car title loan on Jun 14, 2011 8:21 PM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
This site is very interesting and also great. I'm glad to find out this ste immediately. It's very informative.
Left by rim financing on Jun 14, 2011 8:22 PM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
Hello, I love reading through your post, I wanted to leave a little comment to support you and wish you a good continuation. Wishing you the best of luck for all your efforts.
Left by acai berry diet on Jun 22, 2011 10:18 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
Its a great pleasure reading your post. Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work .
Left by ischgl on Jun 25, 2011 8:03 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.
Left by Civil War Spies on Jun 28, 2011 4:53 AM

# re: Resolving Special Folders in WiX 3.0
Requesting Gravatar...
Brilliant information. Keep it up!
Left by nedeljni horoskopi on Aug 11, 2012 3:46 PM

Your comment:
 (will show your gravatar)


Copyright © Elton Stoneman | Powered by: GeeksWithBlogs.net