<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Boettr&#039;s Tech Blog</title>
	<atom:link href="http://boettr.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://boettr.wordpress.com</link>
	<description>Just another WordPress.com site</description>
	<lastBuildDate>Fri, 26 Aug 2011 12:23:28 +0000</lastBuildDate>
	<language></language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='boettr.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Boettr&#039;s Tech Blog</title>
		<link>http://boettr.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://boettr.wordpress.com/osd.xml" title="Boettr&#039;s Tech Blog" />
	<atom:link rel='hub' href='http://boettr.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Simple way to encrypt App.Config through WiX 3.5 and VS2010 Using C# code</title>
		<link>http://boettr.wordpress.com/2010/05/20/simple-way-to-encrypt-app-config-through-wix-3-5-and-vs2010-using-c-code/</link>
		<comments>http://boettr.wordpress.com/2010/05/20/simple-way-to-encrypt-app-config-through-wix-3-5-and-vs2010-using-c-code/#comments</comments>
		<pubDate>Thu, 20 May 2010 00:30:42 +0000</pubDate>
		<dc:creator>boettr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://boettr.wordpress.com/?p=3</guid>
		<description><![CDATA[Yesterday I wasted almost a whole day trying to achieve this theoretically very simple task. To save others the same fate I decided to put a few of my experiences up here. During my research I found no shortage of &#8230; <a href="http://boettr.wordpress.com/2010/05/20/simple-way-to-encrypt-app-config-through-wix-3-5-and-vs2010-using-c-code/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=boettr.wordpress.com&amp;blog=13769214&amp;post=3&amp;subd=boettr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Yesterday I wasted almost a whole day trying to achieve this theoretically very simple task. To save others the same fate I decided to put a few of my experiences up here.</p>
<p>During my research I found no shortage of guides claiming to contain simple methods for achieving this task. What I found from reading these guides was that many were only partially complete or were written in different languages for different versions of Visual Studio or WiX. What I will propose here is the use of a small c# application to handle the encryption of the App.config which will be trailed by a small batch file to cleanup unnecessary files. </p>
<p>First step is to create a console application project inside your project solution. Inside the project insert the following into the Main method of the Program.cs.</p>
<div style="width:1063px;display:block;float:none;margin-left:auto;margin-right:auto;padding:0;" id="scid:9EDA38F6-AE13-4003-B74A-83E8474F528D:5500fc2b-3528-471b-a496-9fda2bef04d5" class="wlWriterEditableSmartContent">
<pre><pre class="brush: csharp;">class Program
{
    static void Main(string[] args)
    {
        string configPath = String.Empty;
        const string sectionToEncrypt = &quot;connectionStrings&quot;;

        foreach (String arg in args)
        {
            configPath = configPath + &quot; &quot; + arg;
        }

        configPath += &quot;CONFIGNAME.exe.config&quot;;

        var fileMap = new ExeConfigurationFileMap();
        fileMap.ExeConfigFilename = configPath;
        var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
        ConfigurationSection section = configuration.GetSection(sectionToEncrypt);

        if (!section.SectionInformation.IsProtected)
        {
            section.SectionInformation.ProtectSection(&quot;DataProtectionConfigurationProvider&quot;);
            section.SectionInformation.ForceSave = true;
            configuration.Save(ConfigurationSaveMode.Modified);

        }

    }
}</pre></pre>
</div>
<p>This simple bit of code uses the arguments passed to it from WiX to construct the path of the install folder and find the named config file (the loop is necessary because of the spaces in directory names). It then uses the System.Configuration library to encrypt the connectionStrings section (if desired this same method could be used to encrypt another section). You will need to insert the name of your config file and add references to System.Configuration for this to work. Original credit for the majority of this code must go to JasonS who originally posted it <a href="http://stackoverflow.com/questions/306992/how-do-i-encrypt-app-config-file-sections-during-install-with-wix">here</a>. </p>
<p>Up next I created a simple batch file to delete the encrypt.exe after it had done its business and then delete itself cleaning the install directory of unnecessary files. Create a batch file with the following code and add it to the same project.</p>
<div style="width:967px;display:block;float:none;margin-left:auto;margin-right:auto;padding:0;" id="scid:9EDA38F6-AE13-4003-B74A-83E8474F528D:d1ad304f-a0ae-4702-b5fd-2d250ea3e957" class="wlWriterEditableSmartContent">
<pre><pre class="brush: cpp;">cd %*
del Encrypt.exe
del RemoveAdditionalFiles.bat

</pre></pre>
</div>
<p>The %* for anyone unfamiliar will take all arguments that are passed to the batch file (once again the * is necessary because of the way that console arguments are divided by spaces). This is important because we will be passing the directory from the install to the batch file so it knows where to delete the files from. File names might have to change here based on what you call your batch and encryption program. You will need to access the properties of your batch file in Visual Studio to always be Copied to Output Directory for this to work correctly.</p>
<p>With the code written we now need to hook this up to WiX. start by adding a project reference to the WiX project for the Encryption project. You will then need to add the two output files from the encryption project to the install folder. A simple lesson on how to include files in your WiX installation is covered <a href="http://www.tramontana.co.hu/wix/lesson1.php#1.2">here</a>. Below is the code to hook up the custom actions to occur after the installation is complete.</p>
<div style="width:1015px;display:block;float:none;margin-left:auto;margin-right:auto;padding:0;" id="scid:9EDA38F6-AE13-4003-B74A-83E8474F528D:dc6d8e86-2dc1-4f8c-9ca3-68aa612cf785" class="wlWriterEditableSmartContent">
<pre><pre class="brush: xml;">  &lt;CustomAction Id='LaunchFile' FileKey='EncryptExe' ExeCommand='[INSTALLLOCATION]' /&gt;
  &lt;CustomAction Id='RemoveExtraFiles' FileKey='RemoveFiles' ExeCommand=&quot;[INSTALLLOCATION]\&quot; Return='asyncNoWait' /&gt;

  &lt;InstallExecuteSequence&gt;
    &lt;Custom Action='LaunchFile' After='InstallFinalize'&gt;NOT Installed&lt;/Custom&gt;
    &lt;Custom Action='RemoveExtraFiles' After='LaunchFile'&gt;NOT Installed&lt;/Custom&gt;
  &lt;/InstallExecuteSequence&gt;</pre></pre>
</div>
<p>This code should be placed at the bottom of the WiX file. The FileKey Should be set to the ID of the related deployed file and the ExeCommand should contain the property name of your install directory in square brackets (in my case INSTALLLOCATION).</p>
<p>Hopefully this has provided you all the information you require. Feel free to leave your comments.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/boettr.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/boettr.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/boettr.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=boettr.wordpress.com&amp;blog=13769214&amp;post=3&amp;subd=boettr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://boettr.wordpress.com/2010/05/20/simple-way-to-encrypt-app-config-through-wix-3-5-and-vs2010-using-c-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6976128ea6b6bb7315ab11726fe03cfb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">boettr</media:title>
		</media:content>
	</item>
		<item>
		<title>Hello world!</title>
		<link>http://boettr.wordpress.com/2010/05/19/hello-world/</link>
		<comments>http://boettr.wordpress.com/2010/05/19/hello-world/#comments</comments>
		<pubDate>Wed, 19 May 2010 23:16:42 +0000</pubDate>
		<dc:creator>boettr</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://boettr.wordpress.com/?p=1</guid>
		<description><![CDATA[Welcome to my blog. From time to time I will post my post my programming adventures up here. I hope you find them useful. Richard<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=boettr.wordpress.com&amp;blog=13769214&amp;post=1&amp;subd=boettr&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Welcome to my blog. From time to time I will post my post my programming adventures up here. I hope you find them useful.</p>
<p>Richard</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/boettr.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/boettr.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/boettr.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=boettr.wordpress.com&amp;blog=13769214&amp;post=1&amp;subd=boettr&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://boettr.wordpress.com/2010/05/19/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6976128ea6b6bb7315ab11726fe03cfb?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">boettr</media:title>
		</media:content>
	</item>
	</channel>
</rss>
