Multiple Startup Projects: Stop VS2010 Change To Current Project

If you work on a solution that requires multiple startup projects, you can change that in Visual Studio:

One catch though is that sometimes Visual Studio will switch the Startup project to whatever project you select in Solution Explorer (work on one of its files).

If this happens to you, just select one of the projects as a Startup Project.

This seems to "stop" the automatic Startup Project "Feature" from Visual Studio. Click File -> Save All Files to ensure it’s saved, or even restart Visual Studio.

Of course you’ll need to set the multiple startup projects again after that.


Notes On Using Visual Studio 11 As Primary IDE On Windows 7

It’s been quite sometime since I first installed VS 11 (soon after dev preview came way), so, I thought I’d share my experience around using it as primary IDE (with VS 2010 solutions most of the time):

  • It works nicely with Visual Studio 2010 solutions, even big real-world ones. It doesn’t convert them but does some changes to project files which are backwards compatible (mainly minor formatting changes). Note that from the source-control point of view, those are still changes.
    • Somehow all my IIS 7.5 application pools lost their "Enable 32-bit applications" option very shortly after that. This is too coincidental with Visual Studio 11, although I’m not 100% sure if it was the reason.
      It could be hard to debug, If you start getting errors like "unable to load assembly <some path>.dll. or one of its dependencies. An attempt was made to load a program with an incorrect format.". Check for that option.
  • It works a bit faster than Visual Studio 2010. Maybe because it has fewer plug-ins, but I think if I remember bare-bones Visual Studio 2010 correctly, this Visual Studio 11 one is still (slightly) faster.
  • Not much difference in editor for C#, but nicely improved editor for JS / CSS
  • The real differently looking was the team explorer & TFS features in general – mixed feelings about it
    • Not sure I like how Pending Changes is not a separate window anyone. I have to change the Active View to Work Items to find the query I want, click it, go back to Pending Changes, and then drage the work item I want to associate with changeset
    • The changed files show in folder hierarchy. You have two completely separate hierarchies for “Included” and “Excluded” files in/from the changeset. Makes it easier to avoid “checked-in this file by mistake” errors.
    • When comparing files, finally you get coloring (nice one), one of the modes is combined view (they still have 2, and 3 pane views), which does support live editing.  It’s not just text editing experience you get in some merge tools. It’s context-aware full VS editor experience. Things like intellisence, Go To Declaration, Find Usage, Refactor, etc.. and context menu options including those added by third-party tools like TestDriven.NET are available. .
      I found myself editing files in combined-compare view a lot and it makes it great seeing exactly what I’m changing
  • Needed to make a small hack to get TestDriven.NET working.
  • Of course I miss Resharper!  <– Not anymore! See below…

I generally recommend using it, and think it’s safe and nice if you ask Smile

Visual Studio 2010 Productivity Power Tools: Copy HTML To Windows Live Writer

Just a quick note, if you install Productivity Power Tools For Visual Studio 2010.

It has a nice feature.. Copy code as html. The feature doesn’t add any new menu option or whatever, simply when you copy the code the usual CTRL+C or Edit -> Copy way in Visual Studio, and paste it in a text-only editor like Notepad, it’ll be treated as text normally, but if you paste it in an HTML capable editor like Microsoft Word, it’ll be paste as HTML.


If you already know what the feature is, and have a problem with Live Writer 2011 or similar version, you can skip to the title that mentions it.


  • If you wonder how  made this rectangular selection, you can do it by pressing ALT before selection and holding as you move the mouse to continue to select
  • If you wonder why, simply to avoid the spaces on the left in the pasted code

If I paste this in notepad, nothing new!



But if I paste in Word 2010 (Outlook is the same)


(it can be better if play with font size and text wrapping options)


Or in Visual Studio HTML Designer



If I paste in source view or any other code-editor view in Visual Studio, it WILL not paste as HTML but as normal text. This is intended, because when you do copy / paste inside Visual Studio, you want it to just work, not have to clean all generated HTML

This is related to the way this feature works. In Windows, you can have multiple formats of copied stuff in clipboard. Text and HTML are two of these formats. So, the feature is simply adding HTML format option to the clipboard, and Visual Studio built-in functionality of course adds the text format already.


Windows Live Writer

Obviously Windows Live Writer is an HTML editor for blog posts, among other features. And I bet it is as obvious that the most common use of this Copy HTML feature is to embed in your blog posts.


Putting code in blog posts this way has its own disadvantages and disadvantages. Those, along with whether you should use this approach or not, are beyond the scope of this post.

The Problem

If you try to paste the code in Windows Live Writer using CTRL+V, here is what you get:


Hmm.. This is not just text (notice font type) and not complete style.

Let’s see the source for that…


This is quite confusing, isn’t it? Clearly it DID realize we have some HTML, but the result has nothing to do with what we we have in Visual Studio at all !!


The Supposed Non Working Fix

If you look at the official announcement of the feature. or StackOverflow question like this (before I reply to it, months after the guy marked the correct solution already), you notice it says you need to paste using CTRL + SHIFT + V, not just CTRL + V. It means "Paste Special".

You go enthusiast to Live Writer to give it a try, you press CTRL + SHIFT + V, ALT + K. But you may encounter the same other problem as me, it doesn’t work, at all, at least in my Windows Live Writer 2011.


The Solution

Well, after looking for the the "Paste Special" feature in Windows Live Writer, it was very close to me, in the context menu (right click inside text editor)



When clicked, we get the dialog in the official announcement, by default it selects the 2nd option, but we should select the 3rd, "Keep Formatting"



And here we go…



Works as advertised!



Copy HTML Visual Studio Productivity Power Tools Feature Settings

Let’s look at the code we got inside Windows Live Writer (it doesn’t matter which application I guess)…


As you can see, this is really ugly code, so many <span> tags with inline styles, and even <font> tags (thought no-body uses them anyway) and so on.

You can argue this is normal in this way of adding code to blog. You can argue this is why you should ignore this way completely. I’d ask you to have this discussion in the great post Scott HAnselman wrote about this and other approach in this case, but assuming we continue with this one, let’s see what we can and what we cannot improve here…


In Visual Studio, Go To Tools -> Options, from the right side tree, navigate to Productivity Power Tools -> HTML Copy:



The first two options are like header / footer of the code. Those are the opening and closing tags of the generated HTML code. You can change them as you like, for example, for me, I’d add <code> tag around those since I have some extra CSS applied to this tag boxing style ad want my snippets to take it.


The emit spam class will not use CSS styles if you sett to true, instead, will use certain CSS classes. Do not select it unless you know what the CSS classes are and have their styles. Also, if you add those styles to the blog CSS, it won’t show in RSS readers, and if you put in each post, it just feels wrong – again choice is yours after you read Scott’s post.


The emit spam style is what created us the inline CSS. This is the default and unless you care about minimizing the noise you’ll be interested in trying the previous option and disable this one.

You’ll want to enable the two if you are testing to see what inline styles will apply to <span> tags with which CSS classes.


The option to replace line-breaks (new lines) with <BR> is something you normally won’t set to true. You can see the default surrounding tags include <pre>, and <pre> tag in HTML reserves spaces and line breaks, unlike other HTML tags.

If you keep the line breaks and the <pre> tags, the code will be displayed properly in your blog, and when someone tries to copy it to their code editor (Which understands text only, even Visual Studio source/code editor as mentioned above) the line breaks will work correctly, but if you use <BR>, the text editor will not see them (As this is HTML not text) and will render multiple lines in only one, and the poor reader will need to add the line breaks on his own.


The last option is what letter or code is used for space s(Assuming even tabs will convert to spaces).By default it uses the HTML code for spaces &nbsp;. If you are keeping the <pre> tag in your generated HTML, you can replace this with normal real SPACE letter (just replace the value in text box with one press on the space-bar in your keyboard). Since I recommend keeping the <pre> tag anyway, I recommend you use spaces directly too.



I noticed that with different plugins and options to render code in blog with Windows Live Writer, it quite affects the stability of the application. You can see it easily crashing when you move between Edit/Preview/Source views.

Windows Live Writer has a nice recovery feature that usually work (sometimes insists on offering to recover what I recovered already. but that’s fine). However, you should also save yourself a piece of mind and press CTRL + S every now and then and specially before switching views. I press it all the time like crazy every line or less!



BTW, this is how the code looks for me on THIS blog:

<font face="Lucida Console"><span style="color: " class="keyword"><font style="background-color: #000000" color="#cc7832">public</font></span></font><font color="#f9f9f9"> </font><span style="color: " class="keyword"><font style="background-color: #000000" color="#cc7832">static</font></span><font color="#f9f9f9"> </font><span style="color: " class="keyword"><font style="background-color: #000000" color="#cc7832">void</font></span><font color="#f9f9f9"> <span class="identifier"><font style="background-color: #000000">RegisterRoutes</font></span>(</font><span style="color: " class="User Types"><font style="background-color: #000000" color="#ffc66d">RouteCollection</font></span><font face="Lucida Console"></font><font color="#f9f9f9"> <span class="identifier"><font style="background-color: #000000">routes</font></span>)
    </font><font style="background-color: #000000"><span class="identifier">routes</span><span class="operator">.</span><span class="identifier" style="color:#f9f9f9;">IgnoreRoute</span></font>(<span style="color: " class="string"><font style="background-color: #000000" color="#a5c25c">"{resource}.axd/{*pathInfo}"</font></span><font face="Lucida Console"></font><font color="#f9f9f9">);

    </font><font style="background-color: #000000"><span class="identifier">routes</span><span class="operator">.</span><span class="identifier" style="color:#f9f9f9;">MapRoute</span></font>(
        <span style="color: " class="string"><font style="background-color: #000000" color="#a5c25c">"Default"</font></span><font color="#f9f9f9">, </font><span style="color: " class="comment"><font style="background-color: #000000" color="#808080">// Route name</font></span>
<font color="#f9f9f9">        </font><span style="color: " class="string"><font style="background-color: #000000" color="#a5c25c">"{controller}/{action}/{id}"</font></span><font color="#f9f9f9">, </font><span style="color: " class="comment"><font style="background-color: #000000" color="#808080">// URL with parameters</font></span>
<font color="#f9f9f9">        </font><span style="color: " class="keyword"><font style="background-color: #000000" color="#cc7832">new</font></span><font color="#f9f9f9"> { <span class="identifier"><font style="background-color: #000000">controller</font></span> <span class="operator"><font style="background-color: #000000">=</font></span> </font><span style="color: " class="string"><font style="background-color: #000000" color="#a5c25c">"Home"</font></span><font color="#f9f9f9">, <span class="identifier"><font style="background-color: #000000">action</font></span> <span class="operator"><font style="background-color: #000000">=</font></span> </font><span style="color: " class="string"><font style="background-color: #000000" color="#a5c25c">"Index"</font></span><font color="#f9f9f9">, <span class="identifier"><font style="background-color: #000000">id</font></span> <span class="operator"><font style="background-color: #000000">=</font></span> </font><font style="background-color: #000000"><span style="color: " class="User Types"><font color="#ffc66d">UrlParameter</font></span></font><font color="#f9f9f9"><span class="operator">.</span><span class="identifier">Optional</span></font><font color="#f9f9f9"> }


Of course you know how to view source in your browser Smile


BTW, this was NOT the blog post I wanted to have done this week. There is another one in the works, about how easy it is to work classes and converting them to different formats like JSON.

If you know my public Github URL, you can get the code already, if not, stay tuned till this weekend or so Winking smile

How to export settings from Visual Studio 2010 to Visual Studio 2008

This is particularly helpful when you want to copy colour settings / Visual Studio theme from one machine to another or across different versions of VS you have (say at your laptop and some customer’s PC)

Simply get the VS2010 import file, right click, open with, choose a program, and pick any simple editor, say Notepad


Yeah, you got it, what you need is to change:

    <ApplicationIdentity version="10.0"/>


    <ApplicationIdentity version="9.0"/>

Now you can use that in VS2008 Without any problem…

Visual Studio “Run As Administrator” Only From Shortcut


Last week I had to re-install Windows. I haven’t done it in a while, so, had to remember all those “1 time” tips I do after reinstall. For example, downloading SQL Server Developer Edition before Visual Studio to get the full Management Studio. Another example, setting Visual Studio to pin to the Start menu, and configuring it for UAC.

The Problem

In the very first year of Windows 7, I used to have many problems with UAC on and always disabled it, later, things started to get better and it became my normal config to leave it on. One problem that remained is that if you have a program set to always “Run AS Administrator”, if this program has associated files (can open files with certain extensions if you click the files), you no longer can open those files directly.

So, like many, I do pin visual studio to the Start menu


I also need to set it to “Run As Administrator” in so many times (for stuff with built-in IIS, not much is on IIS Express).

I right click the shortcut, go to “Compatibility” tab, and check “Run this program as an administrator”.


Note that this if done with any shortcut to Visual Studio devenv.exe file, has the same effect of doing it on the EXE directly, which is making the EXE require Admin permissions whenever run.


The problem is, when I do that, clicking any .CS or .SLN file doesn’t work in Visual Studio…


So, I had either the option to remember to open Visual Studio as Administrator when required (and restart it if open without Admin privileges) or I have to open files only from Start menu shortcuts and pinned shortcuts and VS File –> Open


Both are bad, because it’s very common for me to work on projects when I’m confortable with having VS run as admin, and many times also I get source code from the Internet and I just want to click an SLN file in Windows Explorer or even a CS file inside zip/rar file and quickly browse the code in the solution / file.


The Solution

One thing I discovered later, is that you can actually set only a shortcut to open the EXE as administrator, so that other shortcuts and the System itself opening the EXE will not require that permission.


So, how can you do that? I right click the shortcut, choose “Properties” as usual, but this time I go to another tab, “Shortcut”, then click “Advanced”, and then check the OTHER “Run as administrator” checkbox:



The plan is simple. I apply this to the shortcut pinned to the Start menu and the task bar, so, whenever I click any of those, I get Visual Studio running as Administrator, but, when I open a file from Windows Explorer or Zip/Rar file, I do NOT run VS as Administrator (because as mentioned above, it won’t work anyway).



This is not much of a very secret trick or something, but I’m trying to get back to blogging more and more by writing anything that comes to my head like this one. You ideas are always welcome either on this one or on other topics you might want me to blog about.



#NHibernate 3.1.0 on #NuGet – Important Details

If you don’t know what is NuGet, please skip to the end first

NHibernate Package

For some time NHibernate 3.0 package on Nuget was listed as owned by Fabio Maulo (@fabiomaulo), a main comitter to NHibernate, but was not owned by him until NHibernate 3.1 came out and there was a need to upgrade the package, which happened today.


You can find NHibernate package on Nuget by searching for the word NHibernate in the gallery, or going to the package page directly on :

Do Not Install This Package Directly

However, in this page (or summary pane in Nuget tool in Visual Studio when you select the package, you’ll read:

DONT INSTALL IT DIRECTLY Only as reference for others frameworks. NHibernate is a mature, open source object-relational mapper for the .NET framework. It’s actively developed , fully featured and used in thousands of successful projects.

Why Is That?

The reason for that is that NHibernate requires using something called a proxy factory. This is the tool that creates proxies of your entities (usually in runtime) for things like Lazy Loading to work. NHibernate has built-in support for those proxy factories, Castle Dynamic Proxy, .LinFu Dynamic Proxy, Spring AOP Framework.

So, What Should I Install ?

What you should actually do is to choose whether you want to use the Castle, LinFu, or Spring proxies, and based on that, install one (and –typically- only one) of the following packages:


NHibernate.Castle –

NHibernate.LinFu –

NHibernate.Spring –


Those packages all created by Fabio as well and depend on the main package. I will not give any differentiation between them and/or when to use them, but maybe if you use FluentNHibernate, you’ll want to use Castle Dynamic Proxy as this is their default.


FluentNHibernate/ConfORM & Other Libraries Depending on NHibernate

The way NHibernate package works from now on will make it a bit confusing to get other packages. For example, if you want to get FluentNHibernate / ConfORM, you will find that it explicitly depends on NHibernate package, but in the same time you are likely to need to install any of the other proxy-specific packages which is not set in the package dependencies.

The creator of FluentNHibernate may decide to depend on a proxy specific package instead, but this will be a problem if another NHibernate-dependent library may decide to depend on another proxy-specific package and it becomes a mess. So, I guess library creators will better not do that and we’ll need to live with the non-explicit dependency that is still likely required.



There is a really nice article on how to install for how to install NHibernate 3.0, and Windsor both from NuGet on ASP.NET MVC projects, The same rules though apply to NHibernate 3.1 and other types of projects than ASP.NET MVC.’

Create an ASP.NET MVC application with Windsor and NHibernate at the speed of nuget

Other than that, there is something you need to be careful of, assembly versions:


Installing Libraries That Depend on Specific Earlier Version of NHibernate|

Covers FLuentNHibenrate

Let’s take FluentNHibernate a an obvious example. FluentNHibernate package on NuGet is set to depend on a pre-release version of NHibernate 3.0. Not much changed in the FluentNHibernate library since then that will make you worry, so, to install it you need to do the following:

  1. Install one of the proxy packages, preferably NHibernate.Castle since this is the default in FluentNHibernate
  2. Install FluentNHibernate (don’t install it first so that it doesn’t just install old version of NH package as dependency)
  3. Apply Assembly Binding Redirect (see below)


Assembly Binding Redirect

Assembly Redirect is a way in .NET that you can use if you reference an assembly with specific version , and you want to use a different version of this assembly without recompiling your code or anything, you can tell .NET to redirect any request for the old version of the assembly to the new one. This is exactly what FluentNHibernate and any library that references specific old version of NHibernate need to do.

God news is, NuGet can setup the correct assembly redirects for you. In the current version of NuGet you need to explicitly call this functionality though. Next version of NuGet will run it automatically when you install a package.

Here is how to do it:


Make sure you build your solution once after adding the packages and before you do this, or else, the NuGet command will not do anything!

From VS 2010, Go to tools –>


The NuGet consolse will show up – Make sure the project you installed NHibernate and FluentNHibernate to is the one selected in the console:


Then type “Add-“ (no quotes) and press TAB, you’ll get intellisense, choose from there “Add-BindingRedirect” (no quotes) and press ENTER.


This should get you the following result (If not, try to build your project and do it again):


Now, you should find you application configuration file (web.config for web projects, app.config otherwise) having a similar section to this one (NuGet will create the file if not exists):


This is the assembly redirection that should allow things to work. Try it!


Other Notes


What Libraries on Nuget are updated to support NHibernate 3.1?

By the time of writing, the only package that supports NHibenrate 3.1 package is ConfORM (also created by Fabio

ConfOrm –


What is NHibernate.Linq Package?

There is another package on NuGet called NHibernate.Linq. Do NOT install this package is you work with NHibernate 3.x. This is the old LINQ provider that is created for NHibernate 2.1, and is no longer maintained.

LINQ support is now built into NHibenrate itself, not any separate package.


Boring Introductions Pushed To The End

If you feel lost going through this post, check out the below questions. If you still have confusion, just leave a comment with your question.


What is there in NHibernate 3.1.0?

Starting NHibernate 3.0.400, NHibernate ORM had interesting features like LINQ support and new query API called QueryOver, as long as hooks for writing entity mapping by code (as used in another library called ConfORM).

NHibernate 3.1.0 adds more LINQ support for more use cases, and adds more bug fixes and improvements on the same paths as 3.0.


What is NuGet?

If you know Ruby/Rails, it’s enough to say it’s Microsoft equivalent of Ruby Gems. Since few of my readers are Ruby guys. I’d explain this by saying it’s a tool that allows you to get software libraries (like NHibernate, Log4Net, Entity Framework 4 Code First CTPs, Castle Windsor etc..) from central repository (feed) where they are published. It allows you to get the library and all its dependencies (for example, NHibernate depends on Iesi.Collections) at one time without having to worry what those are. Each library is expressed by a package, where the package creator can include the library as code or binary and define library version and dependencies of other libraries/packages, and you just point your Visual Studio at the package and get them all, and easily update to future versions later.

It also comes with a PowerShell console inside Visual Studio that allows you to run those commands via scripts and do some interesting things like have libraries that support different versions of dependencies than the latest versions to support those latest versions by assembly redirection.

You can learn more about NuGet by going to

[Link] Python Tools for Visual Studio – Beta

As usual Python stuff for .NET is more advanced and evolving quicker than Ruby stuff.

Sad fact to me as (syntax-wise), I like Ruby much more!


Important: Read Installation Details Below




I haven’t tried yet but what they claim for IDE features specifically is really impressive (if works as in screenshots).


They also support multiple Python runtimes/environments (CPython, different versions of IronPython, PyPy).





Before download, make sure to read the installation details carefully:

Installation Details (See the wiki page):

PTVS is an add-in for Visual Studio 2010. To get Visual Studio you have several options:


  • Get it through your school: You might already have a license for VS – please contact your sys admin or professor.

Set Visual Studio to use your default proxy & credentials to access Extension Manager & NuGet Restore


The instructions have been tested on Visual Studio 2010, 2012, 2013, and 2015.

In VS 2010, extension manager is part of a nice new generation of VS plug-in system. One of the great features of it is how it can go online talk to Microsoft Visual Studio Gallery website to retrieve list of extensions there, automatically discovering updates for installed extensions, and allowing me to add new extensions directly from within Visual Studio.

The Problem:

However, in my company I could not take benefit of that for long time. Reason is, the company uses Blue Coat proxy, with some active directory based authentication. We cannot access the Internet unless we use that proxy, no direct connection allowed, most other proxies are also blocked (by blocking the common proxies port 8080 and many other common ports).

Although I have the proxy set in Internet Explorer, and I have the username/password stored in my Windows Credentials store  (Start–> Run–> Control PanelAll Control Panel ItemsCredential Manager) -since my primary work laptop and user account on it are not part of the company domain-, Visual Studio did not seem to be able to use that.

Anything that requires online communication not directly using the browser is not working. The main feature missed by this is Extensions Manager integration with the Visual Studio Gallery online.


Another side effect of the problem was when running tests with TestDriven.NET test runner (running using Debugger or In-Process), as I had some tests that required connecting to online websites.


The Cause

It turns out (just by guessing and trial-error way) that the default proxy settings for .NET apps is for some reason not to use the system proxy and credentials. Visual Studio will be default ignore that proxy (and many other .NET applications will).


The Solution

Thanks God, .NET applications have a nice extensibility feature for things like this using the app.config file (if it was unmanaged application, I’d have no way to it).


Troubleshooting this issue in TestDriven.NET was what inspired me to get this, as I was trying to setup the credentials in the app.config file of the test project and then in Visual Studio.


So, I needed to setup the proxy settings in the Visual Studio config file., Knowing the Visual Studio IDE executable “devenv.exe”, the file I’m looking for is “devenv.exe.config”. I didn’t need to create that file (which is easy, just a standard .config file with the same name as the executable including “.exe”) because Visual Studio already has a config file with bunch of existing configuration defaults.


I want to the Visual Studio 2010 shortcut in Start-> All Programs, right clicked it, then chose “Properties”.

In the following properties Window, I clicked “Open file Location”:



This took me to the Visual Studio folder that has the “devenv.exe” and “devenv.exe.config” files:



I opened this file in Visual Studio (yes, it’s OK – the effected showed after restarting VS of course):

The section I was looking for is under “<>”. The config file already had this section to enable IPv6 (which is not enabled by default, yet another interesting default and override – I commented the override anyway later).


I modified it with this simple change:



The complete XML for copy-paste sake:

        <defaultProxy useDefaultCredentials="true" enabled="true">
          <proxy usesystemdefault="True" />

As you can see, this is very simple. It enables the proxy, tells Visual Studio to use the system (IE) oroxy, and to use the default credentials for that.


This was all required to do the trick. You just need to close Visual Studio and re-run it afterwards to take effect.


Hopefully this saves someone else facing a similar issue…

EgyGeeks Today’s Gathering, Delivering jQuery and ASP.NET. Open Talk About VS2010

Just wanted to give you a quick update on our next gathering today.

We’ll have the meeting in the same time like last week.

Today, Friday, April 16, at 11:59 PM.

The gathering will have the same style as the last one:

– The first 30 minutes will be a session: Jquery for ASP.NET Developers, by me

– The following 30 minutes will be an open talk, mainly around: Visual Studio 2010 Enhancements

So far we agreed to have the gathering the same way like last week (Using WEBEX website).


We’ll send you the URL by the exact time or the gathering, via the newly created EgyGeeks twitter account.


Also, follow this account for all upcoming gatherings’ news and announcements.