Conditional compilation symbols in Microsoft Visual Studio

If you need to make breaking changes in your source code that will be deployed later to production, but first have to be tested in the development environment you can include conditional compilation symbols to specify which lines will be included in the application for certain environments. This way you can maintain environment specific versions of the source code, the current version for  production and the new version for development and testing.

In this example we will make a change in our source code that we want to deploy to the Development environment for testing, but not to QA, UAT and Production.

Create the conditional compilation symbol in the project

  • Right click the project
  • Select Properties
  • On the left side select the Build tab
  • Select Dev in the Configuration dropdown
  • Enter new_version into the Conditional compilation symbols field

visual studio conditional compilation symbol in project


Add the conditional compilation symbol to the source code

  • Surround the old and new code with a #if, #else, #endif structure

#if new_version

// New code
int a = 1;


// Old code
int a = 0;


int b = a;

If the Dev configuration is selected the new code will be compiled into the application

visual studio conditional compilation symbol true


If another configuration (QA) is selected the old code will be compiled into the application

visual studio conditional compilation symbol false

Microsoft Visual Studio editor settings

There are some settings that can make your work easier in Visual Studio.

Start Microsoft Visual Studio, and in the “Tools” menu select “Options”

– To insert new tabs to the right of existing tabs and keep the already opened tabs in place and
– Show pinned tabs in a separate row

  • On the left side select “Environment”, “Tabs and Windows”
  • Check “Insert new tabs to the right of existing tabs” and “Show pinned tabs in a separate row”

visual studio options tabs


– To use tabs instead of spaces in edited files

  • On the left side select “Text Editor”, “All Languages”, “Tabs”
  • Select “Smart” and “Keep tabs”

visual studio options tab settings


Unable to open a setup project in Microsoft Visual Studio 2010 on Windows 7 64 bit

I work on multiple computers using different operating systems.
When I tried to open a web service solution in Microsoft Visual Studio 2010 on my Windows 7 64 bit workstation I got the following error message:

“The project file … has been moved, renamed or is not on your computer.”

visual studio 2010 unable to open project long path

I could verify that the file was on my computer at the stated location, and I could open the same solution in Microsoft Visual Studio 2010 on a Windows Server 2003 32 bit machine. I have recreated the setup file on my Windows 7 64 bit machine, and everything looked all right, but when I closed the solution and tried to open it again I got the same error message. I have counted the length of the full path of the setup project and I got 153. As it turned out, the path was not too long.

The following steps solved the problem, but I still don’t know why:

  • Removed the setup project from the solution
  • Renamed the setup project file by changing one character of the file name (not the extension)
  • Re-added the setup project as an existing project

How to modify a WordPress theme

There are two ways to modify a WordPress theme: the fast way and the smart way.

The fastest way is to edit the files of the theme by selecting the files with the “Appearance”, “Editor” menu option. The drawback is that when the theme is updated your customizations will be wiped out. The update process will overwrite the files you changed, so all of your changes will disappear.

A better way of modifying a theme is to create a “child theme”. This has two advantages:

  1. By creating a child theme you maintain the changed files in a separate theme (the child theme) so when you update the original (parent) theme your customization is not affected.
  2. You keep a separate copy of your changes in the child theme, so you can always easily find your modifications without reading through the theme files. You will only maintain the changed lines from the style.css file and your functions.php file will only include your custom functions. Your images folder will only contain your image files.


In this tutorial we will create a child theme for the Simplify theme

  • Use your favorite FTP application (mine is FileZilla) and create a folder for the child theme in the wp-content/themes folder
    • Right click the “themes” folder and select “Create directory”

filezilla create directory


  • Enter the name of the folder of the child theme

filezilla create directory name


  • Double click the new folder name to open it

filezilla navigate to directory


Right click the empty area of the directory listing and select “Create new file”

filezilla new file


Enter style.css as the file name and click OK

filezilla new file name


  • Log into your site as administrator,
  • Navigate to the Theme Editor,

wordpress appearance editor select


  • In the upper right corner select the child theme and click the Select button

wordpress theme editor select theme


  • In the upper right corner click the “Stylesheet” to open the style.css file

wordpress theme editor select styles file


Copy the following to the editor window.

  • Enter the name of the new child theme to the “Theme Name” line
  • Replace “simplify” with the name of the original theme folder.


Theme Name:     Simplify Child
Theme URI:
Description:    Child theme for the Simplify theme 
Author:         Your name here
Author URI:
Template:       simplify
Version:        0.1.0
@import url("../simplify/style.css");


  • Click the “Update File” button to save your changes

wordpress theme editor update file


Select and activate the new child theme

  • On the left side select “Appearance” , “Themes”

wordpress themes select


  • On the theme list click the empty image of the new child theme you just created

wordpress themes select child theme


  • Click the “Save & Activate” button to activate the child theme

wordpress theme activate




For more information see:

How to set the application pool automatically during Microsoft Visual Studio 2010 web application and web service deployment

During the Visual Studio 2010 Web Application and Web Service deployment the prior setting of the application pool name is lost. The installer does not assign the correct application pool to the virtual directory, it will be assigned to the Default Application Pool.

If different .NET versions are assigned to the same application pool, the older .NET applications stop working.

To handle this problem in the VS 2010 msi file follow the steps below.

  1. Remote desktop into the web server and in the IIS manager create an application pool for your web application.
  2. Save the following program as SetAppPool.vbs to a common location in your file structure
    ' Sets the Application Pool of the Virtual Directory
    ' Usage:
    ' Right click on the Web Setup project
    ' Select Add, File
    ' Select C:\TFS\HALTeam\Other\Deployment_Tools\SetAppPool.vbs
    ' Right click on the Web Setup project
    ' Select View, Custom Actions
    ' Right click on Commit and select "Add Custom Action"
    ' Select the SetAppPool.vbs file in the Web Application Folder
    ' In the Properties window of SetAppPool.vbs enter the CustomActionData:
    '   Example: /vdir:HALGraphicUpload /appPool:HALGraphicUpload
    Option Explicit
    Dim customActionData, customActionArray, vdirName, appPool, vdirObj
    ' Read the CustomActionData of the Installer
    customActionData = Session.Property("CustomActionData")
    ' Parse the data from the CustomActionData
    customActionArray = Split(customActionData) ' Splits by the space
    vdirName = Replace(customActionArray(0), "/vdir:", "")
    appPool = Replace(customActionArray(1), "/appPool:", "")
    ' Set the Application Pool property of the Virtual Directory
    set vdirObj=GetObject("IIS://localhost/W3svc/1/Root/" & vdirName)
    vdirObj.Put "AppPoolId", appPool



  3. Add the SetAppPool.vbs file to the Setup Project
    1. Right click the setup project
    2. Select “View”, “File System”
    3. On the left side right click the “Web Application Folder” and select “Add”, “File…”
    4. Browse to the “SetAppPool.vbs” file
  4. Add a custom action to the setup project
    1. Right click the setup project
    2. Select “View”, “Custom Actions”
    3.  Right click on “Commit” and select “Add Custom Action”
      1. Double click the “Web Application Folder”
      2. Select “SetAppPool.vbs” and click the “OK” button
    4. On the left side of the screen right click”SetAppPool.vbs” and select “Properties Window”
    5. Enter the following into the CustomActionData field
      (make sure there is only one space before /appPool and there are no other spaces and quotes in the text)

How to set up Internet Explorer to debug with Microsoft Visual Studio

When you debug your Visual Studio web application you want to start and stop Internet Explorer automatically when you start and stop the debugging session. With the default settings Internet Explorer starts automatically when you start debugging, but it does not close when you stop the execution.

To enable the automatic stop, enable debugging in Internet Explorer:

  • Start Internet Explorer,
  • On the upper right corner click the gear icon to open the Tools menu,
  • Select “Internet options”,

internet explorer internet options select


  • On the “Advanced” tab of the Internet options window uncheck “Disable script debugging (Internet Explorer)”
  • Click “OK”.

internet explorer debug enabled


Next time when you debug in Microsoft Visual Studio Internet Explorer will start and stop with the debugging session. When you close Internet Explorer it will stop the debugging session in Visual Studio.

How to delete a folder from the Subversion database in the TortoiseSVN client

If you don’t need a folder in the Subversion database anymore follow the the steps below.

If you are using the TortoiseSVN Subversion client

  • Start Windows Explorer,
  • Right click any folder,
  • Select “TortoiseSVN”, “Repo-browser” to open the repository browser.

TortoiseSVN repo browser select


In the repository browser:

  • Right click the folder you want to remove,
  • Select “Delete…”

TortoiseSVN repo browser folder delete


Enter a message and click the “OK” button.

TortoiseSVN repo browser folder delete message


How to exclude a project folder from the Subversion database

If you added the AnkhSVN – Subversion Support for Visual Studio from you can easily version your files as you develop them.

In your application there could be projects or folders that you don’t want to include in source control.

To ignore the changes in a project open the Solution Explorer in Visual Studio 2010,

  • Right click the project that you want to exclude from source control
  • Select “Project File”, ‘”Ignore”, “Ignore Folder”

visual studio subversion project ignore

New files are not displayed when I click the “Add Items to Folder” button in the Source Control Explorer of Microsoft Visual Studio 2012

To add items to source control in Microsoft Visual Studio 2012 open the Source Control Explorer and  click the “Add Items to Folder” button on the tool bar.

If a folder is selected Visual Studio does not display the new files in the current folder:

visual studio 2012 source control explorer add folder selected


To be able to add the new files from the current folder, click somewhere on the background of the file list, so no item is selected, and click the  “Add Items to Folder” button again:

visual studio 2012 source control explorer add nothing selected

Convert Microsoft Visual Studio applications to version 2012

When Microsoft releases a new version of Visual Studio developers would  like to use the new features of the new IDE. Usually the new version of Visual Studio converts the solution and project files to a new format to be able to save the new settings of that version of the IDE. More seasoned developers already experienced this conversion madness multiple times migrating their applications from VS 2003 to VS 2005 to VS 2008 to VS 2010 and now to VS 2012. Knowing the past we can predict that this trend will continue in the foreseeable future, so it is better to be prepared and set up our applications for easy conversion from the get go.

This post explains how to convert an application from Microsoft Visual Studio 2010 to 2012.

First prepare your application for the conversion. Read the  “How to set up Microsoft Visual Studio solutions for easy conversion…” post to get all the details step-by-step.


Copy the project folder

For every Console Application, Windows Service and Class Library project make a copy of the Project_2010 folder as Project_2012

visual studio convert to 2012 project copy project folder

Remove the read only attribute from the folder and all sub folders and files in it:

  • Right click the Project_2012 folder and select “Properties”
  • In the Properties window clear the “Read only…” check box and click “OK”

visual studio convert to 2012 project remove read only


Click OK on the next window to remove the read only flag from all files and the sub folders too.

visual studio convert to 2012 project remove read only subfolders


Open the “Project_2012” folder and delete the “bin”, “obj”  folders and the “.csproj.vspscc” TFS file.

visual studio convert to 2012 project delete files


Copy the web project file

For Web Applications and Web Services make a copy of the …_2010.csproj web project file as …_2012.csproj and remove the read only attribute from the _2012 version:

visual studio convert to 2012 project copy web project file


Edit the project file in the Project_2012 folder

In Visual Studio 2012 select “Open”, “File…” from the menu,

visual studio open file


  • Click the down arrow on the Open button
  • Select “Open With…”

visual studio open with


  • Select “XML (Text) Editor” and click “OK”

visual studio open with XML


  • In the project file replace “_2010” with “_2012”. In the replace dialog turn off “Match whole word” to find all occurrences of the _2010 reference.

visual studio replace 2010 with 2012


Add the new “Project_2012” folder to source control.


Copy the solution folder

Make a copy of the Solution_2010 folder as “Solution_2012”.

visual studio convert to 2012 solution copy solution folder


Remove the read only flag from the “Setup_2012” folder and its sub folders as you did it with the Project_2012 folder above.

Delete the “.vssscc” file. Visual Studio 2012 cannot work with setup projects, so also delete the “Setup” folder with the VS 2010 setup project in it.

visual studio convert to 2012 solution delete files


Edit the solution file in Visual Studio

Open the solution file as XML in the “Solution_2012” folder and replace “_2010” with “_2012”  as you did it in the Project_2012 file above.


Open the 2012 solution in Visual Studio 2012

Open the solution in Visual Studio 2012, and click OK on the warning dialog about the Setup project. Visual Studio 2012 does not support the Setup project any more. If you want to create MSI files use WIX to generate them.

visual studio convert to 2012 setup project not supported


To remove the Setup project from the solution right click the setup project and select “Remove”

Make sure all of your projects use the same .NET framework. See the  “Yellow exclamation point next to a project reference…” post for more information.


Add the “Solution_2012” folder to source control.

Make a copy of the Config_2010 folder as Config_2012

  • Remove the read only flag from the Config_2012 folder
  • Add the Config_2012 folder to source control

Modify the config files

For command line executives and windows services

Modify the App.config files in the Config_2012 folder

If the solution was created in Visual Studio 2008 or an earlier version

  • Remove encoding=”utf-8″ from the first line
  • Insert

    <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup>

    into the <configuration> element

If the solution was created in Visual Studio 2010

  • Change the value of the  sku attribute of the <supportedRuntime> element from “.NETFramework,Version=v4.0” to “.NETFramework,Version=v4.5”

For web applications and web services

Modify the Web.config files in the Config_2012 folder

  • In the <system.web> node
    • in the <compilation> element set the value of the targetFramework to “4.5”
      targetFramework="4.5" )
    • in the <pages> element set the value of the controlRenderingCompatibilityVersion to “4.0”
      ( controlRenderingCompatibilityVersion="4.0" )

    <compilation defaultLanguage="c#" debug="false" targetFramework="4.5" />

    <pages controlRenderingCompatibilityVersion="4.0" clientIDMode="AutoID"/>