Tuesday, May 26, 2009

VS 2010 Project Conversion+ Upgrade

Visual Studio 2010 will allow you to move your projects from previous versions of Visual Studios  to VS 2010 with ease, I will call this process as “Converting” the project from VS 200X to VS 2010… 

VS 2010 will also allow you to change your project’s Target Framework Version to .NET 4.0 from .NET 2.0, 3.0 or 3.5…  I will call this process as “Upgrading”…

The reason why VS allows you to deal with these two concepts separately is due to various reasons, some of which can be:

  • You might be ready to use the latest and greatest tooling features of VS 2010 even if you are not yet ready to move to .NET 4.0 just yet…
  • You might have a big solution with various projects and you might want to move few of the project to .NET 4.0 first and then take a staged approach to the rest of the projects…  Obviously you would not want to open various projects in different versions of VS…

Project Conversion-  When you are using projects with .csproj/.vbproj files (e.g. Class Library, Web Application Project etc) then these files typically contain some type of information about VS IDE version example in .csproj file you can see below:

<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>



  In the above example  you can notice that there is msbuild/2003 in the schema namespace… There is also ProductVersion 9.0 in the sample above.  If you examine your project file in further depth you will also find references to the .targets files for the Web Application Projects like below:



 <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />



Notice that the location of the targets file is in above example is in “V9.0” directory in the above piece of xml…  This all needs to be changed to Visual Studio 2010 references (i.e. “V 10.0”) to allow your pre VS 2010 project to use new features of VS 2010. 



The process by which pre VS 2010 (e.g. VS 2008, VS 2005)  project and solution files are modified to move to VS 2010 format is what I am referring to as Project Conversion.



VS 2010 conversion wizard is very similar to how VS 2003/VS 2005 to VS 2008 conversion Wizard use to look like…  To convert pre VS 2010 project to VS 2010 you can double click the project or solution file on a box which has VS 2010 and the conversion wizard will kick off… Following will be the steps that you will see:



Step 1: UI describing that your project will be converted



VS Conversion Wizard



Step 2: Option to back up your project (I would encourage you to create a back up of your project before converting so that you have a copy of your project in case there are any errors in conversion)



VS conversion wizard back up option



Step 3: Summary before the conversion begins



VS Conversion Wizard Summary



Note that so far you have not been asked about your .NET Framework Version.  Do not worry about it just yet and hit the “Finish” button above… You will be allowed to make a decision on whether or not you would like to “Upgrade” your project to .NET 4.0 in the next step.



As soon as you click Finish, the project conversion will kick in the Project Upgrade dialog.



Project Upgrade-  Step 3 of project conversion step is pretty much common to any VS project or solution file, by this what I mean is that some of the things like Product Version, Target File Paths etc are typically required to be changed for most projects including Web Projects… Apart from this step there are certain .NET Framework specific steps required to be done e.g. changes to the project file to indicate which .NET Framework version should be used for the project, similar type of changes in the solution file if need be and additionally for web projects changing the web.config file correctly based on the the framework version you are targeting… These changes are what I am referring to as “Project Upgrade”…



Once you click “Finish” button in Step 3 above you should see the below  Framework Version dialog



Step 4:  Choose whether or not to upgrade to .NET 4.0



choose to upgrade to 4.0



I will click “Yes” on the button above but you can choose to click “No” if you are not yet ready to move to ASP.NET 4.0 on the server.   As the dialog specifies you can change the target framework of your project eventually when you are ready by going to the project properties…



If I click “Yes” my web.config file will be modified to conform to ASP.NET 4.0 format...  None of the additional items that you have added to your web.config file (e.g. appSettings, connectionStrings etc) will be altered but rather most of the assembly references in the web.config file will be modified to 4.0…



In addition with ASP.NET 4.0 there is a need for a new attribute on the compilation tag as shown below:



<compilation debug="true" targetFrameworkMoniker=".NETFramework,Version=v4.0">
<assemblies>
<add assembly="System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Data.DataSetExtensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<add assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<add assembly="System.Xml.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies>
</compilation>



The targetFrameworkMoniker attribute allows VS 2010 to identify that the web is a 4.0 web.  This allows VS 2010 to customize the intellisense, toolbox, references etc to 4.0 for your project. 



As part of this project upgrade VS will automatically inject targetFrameworkMoniker attribute into your web.config file.   For a 4.0 web in VS 2010 and ASP.NET 4.0 this attribute is required, if you try to run a 4.0 web without this attribute in the web.config file then you will get an error  At this point you should get below screen after the conversion is successful.



Step 5: Conversion Complete + Logs Screen



VS 2010 Conversion Wizard Complete



You can choose to open the conversion logs at this time or hit Close…  At this point your project should be ready to be used…



Eventually I will write more about Conversion, Upgrade and details about it but in the meantime I hope this will help…



-Vishal

14 comments:

wilsonmar said...

Are VS 2010 projects backward compatible to VS2008?

Vishal R Joshi said...

Yes the more or less are although not automated you will still be able to manually tweak the project/solution file and open them in VS 2008...

Unknown said...

Can someone tell me how to make 2010 project openable in 2008??

Unknown said...

see http://stackoverflow.com/questions/1368628/blend-3-cant-open-vs-2010-projects

jlo said...

I have a very large (219 projects) solution that is disconected from TFS.
I have checked out the solution, run devenv against the sln file with the /upgrade flag.
In many projects the log says it converted but the is empty.
I manually set this value to 0.
However, when the solution is opened the wizard starts. Eventually VS crashes, usually for low virtual memory.
Some "creative" members of my team were able to create code to do genrally bad things (ie circular references, etc.)

Also we have some files orginally genrated by the "Custom Tools" (ie Proxies) that were manually edited. Part of the Upgrade process seems to involve reprocessing files through the new "Custom Tool".

However, I think most of my code should compile without much additional work. I could address the issues if VS would stop crashing.

Is there a way/tag to mark a project so the Upgrade wizard sees the project as converted ? Manually Editing the *.vbproj ( in bulk )would be an acceptable work-around.

David Penn said...

I am trying to convert a 2008 solution to 2010. There are two web application projects and some class libraries and two 2008 web deploys. All of those appear and are converted. The conversion wizard doesn't list the web applications at all and when it is finished it says they are unavailable and it can't convert that type. Can you not convert a 2008 web application to 2010?

SP said...

hey vishal, in visual studio 2008 we were able to convert a web application project to a class library project by just doing a tweak in the project file, by changing the . Do you know how to do that in visual studio 2010 ?

Vishal R Joshi said...

Hi SP,
I think that is by unloading the project and editing the XML file manually. Then removing the first GUID in the project ID/type field (not the exact name). There are GUIDs seperated by commas, you would need to remove only the first one.
JFYI: This is not formally supported thing to do so please do create a backup and then try the same.
thx
Vishal

Anonymous said...

Hi Vishal,
Thanks for the documentation.I have a question regarding the conversion.I have successfully converted the vs 2005 to vs 2010 application.BUt in my compilation tag there is only line
and no tag is there.Is it neccessary to add assemblies manually to the web.config file or can i just leave it as my apllication is working fine
Thanks,
Ahana

Vishal R Joshi said...

Hi Ahana,
I am assuming you have converted your app to .NET 4. If you have done so then your web.config should be trimmed drastically, so I am not surprised that it is looking empty. This is due to the fact that a lot of the initial assembly information is now moved to root web.config file within .NET 4.
If your app is working fine then I would not worry about doing anything. If your VS intellisense is anytime looks wierd make sure to add targetFramework attribute in the compilation node and then hopefully you should be good.
Thanks
Vishal

subhrajit said...

Hi Vishal,

I am trying to convert VS 2003 .net project into VS2010. But I am getting error inthe VB project file. I don't have solution file for VS2003.

Regards,
Subhrajit

Unknown said...

i am trying to convert VS 2003 .net project into VS2010,
but i am getting errorError Could not load type 'form name'

Anonymous said...

Thank u.......

Anonymous said...

Thanks for providing details on how upgrade will be done.

Thanks,
MKR