How to open SQL files in Visual Studio 2012

The default installation of Visual Studio 2012 cannot open SQL documents when you double click on them in Source Control Explorer.  To be able to do that you have to install the

SQL Server Data Tools  for Visual Studio 2012

For more information visit http://msdn.microsoft.com/en-US/data/tools.aspx

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 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
    vdirObj.SetInfo

     

     

  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
      /vdir:YOUR_VIRTUAL_DIRECTORY_NAME /appPool:YOUR_APPLICATION_POOL_NAME
      (make sure there is only one space before /appPool and there are no other spaces and quotes in the text)

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

Microsoft Visual Studio solution folder structure for easy conversion to the new version of the IDE

Microsoft releases a new version of  Visual Studio every 2-3 years, but most of the enterprise applications have to be operational for years. Many companies developed applications in earlier versions of Microsoft Visual Studio ( VS 2003, VS 2005, VS 2008, VS 2010, or VS 2012 ) and the developers would like to use the new features of the VS 2013 development environment and the .NET 4.5 or higher Framework, but the conversion looks very hard and time consuming. If the application’s lifespan is long, the projects and solutions could be converted multiple times, so it makes sense to prepare your applications for the easiest  migration as soon as possible. Preferably set up all projects and solutions during the initial development phase, so later the conversion will be easy and straightforward.

You can set up your new applications and modify the structure of existing projects and solutions for easy conversion, so when the time comes it will be easy to convert them to the new version of Microsoft Visual Studio.

For console applications and Windows services we will create the following folder structure.

visual studio folder structure console app no middletier

If you need to add a middle tier project to the application to handle the business rules follow the structure below:

visual studio folder structure console app with middletier

For web applications and web services we will leave the project file in the web application folder, so the folder structure will look like this:

visual studio folder structure web app no middletier

If you need to add a middle tier project to the web application for the business rules:

visual studio folder structure web app with middletier

In the first example we will prepare the My Console App console application for the conversion.

The files of the My Console App solution are distributed the following way:

  • The top level “MyConsoleApp” solution level folder contains sub folders for the solution file, and the project files,
    visual studio folder structure console app top level no middletier

 

  • The “Project_2012″ folder only contains the”Config” and  “Properties” folders, the App.config file and the project file

visual studio folder structure console app project folder

The “Source” folder will contain all the source files.

visual studio convert to 2012 source folder content2

Create the folder structure in Windows Explorer and in Microsoft Visual Studio 2012 move all source files to the “Source” folder, so multiple projects can reference them:

  • Open the VS 2012 solution in Microsoft Visual Studio 2012
  • Right click a source file in the solution explorer and select “Remove”
  • In TFS (Team Foundation Server) move the just removed source file from the project folder to the “Source” folder. (If you don’t use TFS or any other source control system use Windows Explorer to move the file.)
  • Important: In the Solution Explorer select the project and above the name of the solution click the “Refresh” button, otherwise Visual Studio 2012 will not let you add the file back to the project from the “Source” folder.

visual studio convert to 2012 project refresh

 

  • Right click the ArchiveCreator project and select “Add”, “Existing Item…”

visual studio convert to 2012 project add exsiting

 

  • Select the source file in the “Source” folder, click the down arrow on the “Add” button and select “Add As Link”. This way the file is not going to be copied back to the project folder, it will stay in the “Source” folder.

visual studio convert to 2012 project add as link

 

  • Repeat the steps above to move all your source files to the “Source” folder and add them to the project as link. A small arrow indicates the the file is added to the project as a link, so multiple projects can reference it.

visual studio convert to 2012 project file link indicator

For Web Applications and Web Services leave the project file in the web application folder, and indicate the Visual Studio version in the file name:

visual studio convert to 2012 web project preparation

Create a Visual Studio version specific folder for the solution and place the .sln file into it. Indicate the Visual Studio version in the name of the folder.

For console applications and windows services:

visual studio folder structure console app solution file location

For web applications and web services:

visual studio folder structure web app solution file location

Multiple setup projects in a Microsoft Visual Studio solution

Sometimes it makes sense the create multiple setup projects in a Microsoft Visual Studio solution if you use the same projects, but you want to create separate MSI files for slightly different functionality. An example would be the processing of audio and graphics files. You can use the same middle tier and backend projects for both processes, but deploy two versions of the application to be able to set up two separate scheduled tasks. This way you can stop them separately and set up different schedules for them.

 

Visual Studio Multiple Setup Projects

 

The two setup projects can coexist, but by default they place the output MSI files to the same sub folder of the setup project: “Release” or “Debug” depending on the configuration. When you start the build of the setup project the compiler deletes all files from the target folder, so if you are expecting two MSI files after the two builds you will be surprised. You will only find the latest build result. The easiest way to handle this is to add an extra folder level in the output file name field of  the setup project properties for the Debug and Release configuration.

 

Visual Studio Multiple Setup Projects Output File Name

 

Send the audio processing MSI to Audio\Debug and Audio\Release, and the graphics processing MSI to Graphics\Debug and Graphics\Release.

How to handle “The target version of the .NET Framework in the project does not match…” warning message in Microsoft Visual Studio

When you build the setup project in Microsoft Visual Studio 2010 you receive the following warning message:

The target version of the .NET Framework in the project does not match the .NET Framework launch condition version ‘.NET Framework 4 Client Profile’. Update the version of the .NET Framework launch condition to match the target version of the.NET Framework in the Advanced Compile Options Dialog Box (VB) or the Application Page (C#, F#).

Cause:

When you add a Setup project to your solution Microsoft Visual Studio 2010 sets two default values that usually don’t match the project settings: prerequisites and launch condition.

These are both set to “.NET Framework 4 Client Profile” and if you set your project’s target framework to “.NET Framework 4” you get the warning message above.

(See the How to solve “The version of the .NET Framework launch condition ‘.NET Framework 4′ does not match…” warning in Microsoft Visual Studio post to handle the error with the incorrect prerequisites.)

Solution:

Change the launch condition in the Setup project:

  • Right click the Setup project,
  • Select “View”, “Launch Conditions”,
  • Expand the “Launch Conditions”,

VS Prerequisites Setup Launch Condition

  • Right click the .NET Framework and select “Properties Window”,
  • In the Properties window set the Version to “.NET Framework 4”.

VS Prerequisites Setup LaunchCondition Properties

 

How to solve “The version of the .NET Framework launch condition ‘.NET Framework 4’ does not match…” warning in Microsoft Visual Studio

When you build the setup project in Microsoft Visual Studio 2010 you receive the following warning message:

The version of the .NET Framework launch condition ‘.NET Framework 4’ does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box.

Cause:

When you add a Setup project to your solution Microsoft Visual Studio 2010 sets two default values that usually don’t match the project settings: prerequisites and launch condition.

These are both set to “.NET Framework 4 Client Profile” and if you set your project’s target framework to “.NET Framework 4” you get the warning message above.

(See the How to solve “The target version of the .NET Framework in the project does not match…” warning message in Microsoft Visual Studio post to handle the problem with the incorrect launch conditions.)

Solution:

Set the prerequisites to “.NET Framework 4”

VS Prerequisites Setup

  1. Right click the Setup project,
  2. Select “Properties”,
  3. Select the “Release” configuration,
  4. Click the “Prerequisites…” button,
  5. Check “.NET Framework 4 (x86 and x64)”,
  6. Uncheck “.NET Framework 4 Client Profile (x86 and x64)”,
  7. Click OK,
  8. Select the “Debug” configuration,
  9. Repeat steps 4 – 7.

How to fix “The OutputPath property is not set for project…” error in Microsoft Visual Studio

When you build your Visual Studio solution you get the following error message:

The OutputPath property is not set for project ‘XYZ.csproj’. Please check to make sure that you have specified a valid combination of Configuration and Platform for this project. Configuration=’Debug’ Platform=’AnyCPU’. This error may also appear if some other project is trying to follow a project-to-project reference to this project, this project has been unloaded or is not included in the solution, and the referencing project does not build using the same or an equivalent Configuration or Platform.

Cause:

When you add a new project to a Visual Studio solution the IDE many times changes the settings in the Configuration Manager. Visual Studio 2010 adds a new solution platform “x86” and sets the platform of the existing projects to “x86”. It can also remove the projects from the build list and change their build configuration.

VS  Configuration Manager Changed Values

Solution:

  • Open the Configuration Manager,
  • For all Active solution configurations:
    • Set the Active solution platform to “Any CPU”.
  • For all projects that  have to be included in the build:
    • Set the Configuration to “Debug” or “Release” depending on the environment,
    • Set the Platform to “Any CPU”,
    • Check the “Build” check box.

Solving “The type or namespace name … could not be found” error in Microsoft Visual Studio

When you compile a .NET 4.0 C# application the following error message appears:
The type or namespace name … could not be found (are you missing a using directive or an assembly reference?)

There is also a warning message :
The currently targeted framework “.NET Framework,Version=v4.0,Profile=Client” does not include “System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” which the referenced assembly ….dll” depends on. This caused the referenced assembly to not resolve. To fix this, either (1) change the targeted framework for this project, or (2) remove the referenced assembly from the project.

Cause:
The project targets the .NET framework 4.0 Client profile, but some functionality in the referenced project is not supported by the Client profile.

Solution:
Set the Target Framework of you project to “.NET Framework 4.0”

  • In the Solution Explorer right click the project and select “Properties”,
  • On the “Application” page set the Target Framework to “.NET Framework 4.0”.