<?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/"
	>

<channel>
	<title>Trevor Power &#187; Visual Studio</title>
	<atom:link href="http://blog.trevorpower.com/index.php/tag/visual-studio/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trevorpower.com</link>
	<description>Software development and other thoughts</description>
	<lastBuildDate>Wed, 16 Jun 2010 07:17:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Displaying the workspace name in Visual Studio 2008</title>
		<link>http://blog.trevorpower.com/index.php/displaying-workspace-name-in-visual-studio-2008/</link>
		<comments>http://blog.trevorpower.com/index.php/displaying-workspace-name-in-visual-studio-2008/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 22:43:49 +0000</pubDate>
		<dc:creator>trevorpower</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Workspace]]></category>

		<guid isPermaLink="false">http://blog.trevorpower.com/?p=190</guid>
		<description><![CDATA[Switching between Visual Studio instances with different workspaces can be very frustrating as it is hard to tell which workspace solution is open. I was planning on writing a plug-in to display the workspace name in the title bar when I found this question on Stackoverflow by someone with a similar problem, Working with different [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fdisplaying-workspace-name-in-visual-studio-2008%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fdisplaying-workspace-name-in-visual-studio-2008%2F" height="61" width="51" /></a></div><p>Switching between Visual Studio instances with different workspaces can be very frustrating as it is hard to tell which workspace solution is open. I was planning on writing a plug-in to display the workspace name in the title bar when I found this question on Stackoverflow by someone with a similar problem, <a href="http://stackoverflow.com/questions/523637/working-with-different-versions-branches-of-the-same-visual-studio-2005-solution">Working with different versions/branches of the same Visual Studio 2005 solution</a>.</p>
<p>One of the comments there suggested the use of &#8216;hard links&#8217; to the solution file. I have given it a go and it has been working quite well for me for that last few days. Here&#8217;s how to do it.</p>
<p>A normal windows shortcut will not suffice, you need to create a symbolic or hard link to the solution file. In Windows 7 you can do this via the command line tool <i>mklink</i>. If you have a workspace called &#8216;Merge&#8217; and a solution called &#8216;MyApp.sln&#8217; the the following command will create a shortcut that you can use. (You will need to run this as an administrator).</p>
<pre>C:\MyApp&gt;mklink MyApp.Merge.sln MyApp.sln</pre>
<p><img class="alignright size-full wp-image-201" title="Multiple Visual Studio Instances" src="http://blog.trevorpower.com/wp-content/uploads/2010/01/Multiple-Visual-Studio-Instances1.png" alt="Multiple Visual Studio Instances" width="456" height="227" /></p>
<p>Now use the new link to open you solution file. Then when you have multiple VS instances open and you click on the Visual Studio task bar icon, you will see the name of your new link (including workspace name or branch name). It also appears in the main title bar.</p>
<p>Have you come across any better solutions? Or easier ways to create links?</p>
<p><b>Update:</b> I wasn&#8217;t sure at first what the difference would be between a hard link and a symbolic link but it turns out that using a hard link (a &#8216;/H&#8217; switch on the above command) helps when you need to save changes to the solution file. But I suggest opening the solution file normally when you need to modify it as saving the solution from the hard link will insert its name into the file.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trevorpower.com/index.php/displaying-workspace-name-in-visual-studio-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sharing configuration settings in Visual Studio</title>
		<link>http://blog.trevorpower.com/index.php/sharing-configuration-settings-in-visual-studio/</link>
		<comments>http://blog.trevorpower.com/index.php/sharing-configuration-settings-in-visual-studio/#comments</comments>
		<pubDate>Thu, 22 Oct 2009 20:30:15 +0000</pubDate>
		<dc:creator>trevorpower</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[app.config]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[web.config]]></category>

		<guid isPermaLink="false">http://blog.trevorpower.com/?p=118</guid>
		<description><![CDATA[Correctly managing your systems settings during both development and deployment can save you a lot of time. When ever you have to manually change settings there is the opportunity to mess up, so I try to automate any repetitive configuration tasks.
It often happens that application settings or connection strings are needed by more than one [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;"><a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fsharing-configuration-settings-in-visual-studio%2F"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.trevorpower.com%2Findex.php%2Fsharing-configuration-settings-in-visual-studio%2F" height="61" width="51" /></a></div><p>Correctly managing your systems settings during both development and deployment can save you a lot of time. When ever you have to manually change settings there is the opportunity to mess up, so I try to <a href="http://blog.trevorpower.com/index.php/2009/02/handling-multiple-web-config-files-in-visual-studio/">automate any repetitive configuration tasks</a>.</p>
<p>It often happens that application settings or connection strings are needed by more than one component in your system. The solution I use is a variation of this method of <a href="http://devlicio.us/blogs/derik_whittaker/archive/2008/04/15/how-to-share-configuration-files-between-projects.aspx">sharing app.config files between applications</a>, except that it allows each project to have its own app.config or web.config files which reference the common settings.</p>
<h2>Creating shared settings</h2>
<p>The first step is to make a settings class that acts as a wrapper around the values in the configuration files. This is a very simple class inheriting ApplicationSettingsBase and looks like this:</p>
<pre name="code" class="c#:nocontrols:nogutter">using System.Configuration;

namespace TP.Example.Configuration
{
    public class Settings : ApplicationSettingsBase
    {
        private static Settings _defaultInstance =
                (Settings)(ApplicationSettingsBase.Synchronized(new Settings()));

        public static Settings Default { get { return _defaultInstance; } }

        [ApplicationScopedSettingAttribute()]
        string ServiceName
        {
            get { return ((string)(this["ServiceName"])); }
            set { this["ServiceName"] = value; }
        }

        [ApplicationScopedSettingAttribute()]
        string EventLogName
        {
            get { return ((string)(this["EventLogName"])); }
            set { this["EventLogName"] = value; }
        }

        [ApplicationScopedSettingAttribute()]
        [SpecialSettingAttribute(SpecialSetting.ConnectionString)]
        string ConnectionString
        {
            get { return ((string)(this["ConnectionString"])); }
            set { this["ConnectionString"] = value; }
        }
    }
}</pre>
<p>The next step is to create the files that contain the settings. I usually have two, one for application settings and one for connection strings. The application settings file consists of a single node matching the full name of my settings class:</p>
<pre name="code" class="xml:nocontrols:nogutter">&lt;TP.Example.Configuration.Settings&gt;
  &lt;setting name="ServiceName" serializeAs="String"&gt;
    &lt;value&gt;My Example Service
  &lt;/setting&gt;
  &lt;setting name="EventLogName" serializeAs="String"&gt;
    &lt;value&gt;ExampleLogName
  &lt;/setting&gt;
&lt;/TP.Example.Configuration.Settings&gt;</pre>
<p>The connection strings file consists of one &#8216;connectionStrings&#8217; node. Note the name of the connection string is qualified with the full name of my settings class.</p>
<pre name="code" class="xml:nocontrols:nogutter">&lt;connectionStrings&gt;
  &lt;add name="TP.Example.Configuration.Settings.ConnectionString" connectionString="[...]" /&gt;
&lt;/connectionStrings&gt;</pre>
<p>These files should exist outside any of your projects but be under source control. I usually put them in a solution folder &#8216;Configuration&#8217; that contains a simple project with the above settings class:<br />
<img class="alignleft size-full wp-image-128" title="'Configuration' solution folder" src="http://blog.trevorpower.com/wp-content/uploads/2009/10/ConfigFolder.png" alt="'Configuration' solution folder" width="351" height="145" /><br clear="all"/></p>
<h2>Referencing shared settings</h2>
<p><img class="alignright size-full wp-image-150" title="Icons have shortcut arrow" src="http://blog.trevorpower.com/wp-content/uploads/2009/10/FilesAsLinks.png" alt="FilesAsLinks" width="326" height="129" />These common settings are now ready to be used by any project in the solution by following these steps:</p>
<ol>
<li>Add a reference to the settings project.</li>
<li>Add a link to settings files and turn on &#8216;copy to output directory&#8217;</li>
<li>Include settings files in the app.config/web.config</li>
</ol>
<p>To link to the settings files you should <em>Add </em>-&gt; <em>Existing Item</em> -&gt; <em>Add As Link</em>, they will then appear with a shortcut icon. This means that they only point to the original file, so there is no duplication.</p>
<p>Now that the files are in our project we just need to get our App.config file to include them. A simplified App.config would look like this:</p>
<pre name="code" class="xml:nocontrols:nogutter">&lt;?xml version="1.0" encoding="utf-8" ?>
&lt;configuration>
  &lt;configSections>
    &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup" >
      &lt;section name="TP.Example.Configuration.Settings" type="System.Configuration.ClientSettingsSection" />
    &lt;/sectionGroup>
  &lt;/configSections>
  &lt;connectionStrings configSource="TP.Example.Configuration.ConnectionStrings.config" />
  &lt;applicationSettings>
    &lt;TP.Example.Configuration.Settings configSource="TP.Example.Configuration.AppSettings.config" />
  &lt;/applicationSettings>
&lt;/configuration>
</pre>
<p>Now when you modify one of these files the change will be picked up by all other projects in the solution.
<p/>
<h2>Websites and Web.config</h2>
<p>Using these settings in a website requires one extra step. As before, the settings file will be linked to by the project file and the &#8216;Copy to Output Directory&#8217; turned on. The problem is that the web.config file is usually at the root while the output directory is &#8216;bin&#8217; or &#8216;bin/Debug&#8217; depending on your setup. Because the output folder can depend on the build configuration, I have found the best solution is to copy the config files from the target directory to the project directory. This is just one line in the build events.<img src="http://blog.trevorpower.com/wp-content/uploads/2009/10/CopyConfigFiles.png" alt="COPY $(TargetDir)*.config $(ProjectDir)" title="COPY $(TargetDir)*.config $(ProjectDir)" width="532" height="267" class="aligncenter size-full wp-image-169" /><br />
Writing it out like this sounds like a lot of work but it is easy to setup and easy to maintain. If you have any question or have a better solution, please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trevorpower.com/index.php/sharing-configuration-settings-in-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
