Your official information source from the .NET Web Development and Tools group at Microsoft.
One of the most requested features of Visual Studio 2012 was the ability to open projects in both VS 2012 as well as VS 2010 (requires VS 2010 SP1). In case you haven’t heard we did implement that feature. You may be wondering how we were able to do this and how this may impact you.
If you open the .csproj/.vbproj for a Web Project created in VS2010 you will see the following import statement.
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\ v10.0\WebApplications\Microsoft.WebApplication.targets" />
When you open this project in VS 2012 there are a few changes made to your project file to ensure that it can be opened in both VS 2010 SP1 and VS 2012. One of the changes made to the project when it is first loaded in VS 2012 is to add the following to replace that import statement.
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
We removed the hard-coded 10.0 and instead used the property VisualStudioVersion. When building in Visual Studio 2012 this value will always be 11.0, but for VS 2010 it doesn’t exist. That is why we defaulted it to 10.0 above.
There are some scenarios where building from the command line will require to set this property explicitly. Before we get there let me explain how this property gets set (in this order)
For #2 when you are building a .sln file the value of VisulStudioVersion will be –1 of the Format Version found in the .sln file. The important thing to note here is that if you build a .sln file it will build with the value of VisulStudioVersion corresponding to the version of VS which created the .sln file. So if you create a .sln file in VS2012 and you always build that .sln file the value for VisualStudioVersion will be 11.0. In many cases if you build the .sln file you are good.
If you are building .csproj/.vbproj files w/o going through a .sln file? If you build a web project from the command line (not the developer prompt) then the value for VisualStudioVersion used will be 10.0. That is an artifact of the properties which I showed above. In this case you should pass this in as an MSBuild property. For example
msbuild.exe MyAwesomeWeb.csproj /p:VisualStudioVersion=11.0
In this case I’m passing in the property explicitly. This will always override any other mechanism to determine the value for VisualStudioVersion. If you are using the MSBuild task in a build script, then you can specify the property either in the Properties attribute or the AdditionalProperties attribute. See my previous blog post on the difference between Properties and AdditionalProperties.
If you encounter any funny behavior when building/publishing and you notice that the wrong .targets files are being imported then you may need to specify this property.
Cross posted to: http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx
Sayed Ibrahim Hashimi | @SayedIHashimi
Huge Kudos for this! Not having to convert the projects and solutions to a new version that breaks compatibility with the previous version of VS is a huge help especially for open source projects. We have lots of people using the source code from our repository but of course we cannot assume that everyone can upgrade to VS 2012 at once so this really helped us because our core dev team was able to upgrade to VS 2012 without worrying that the projects/solutions would not work for others in the community who are still using VS 2010. For those of us who live in VS all day it is very exciting to upgrade to a new version and without this backward compatibility we would probably have had to wait a while. So again huge kudos and thanks to the Visual Studio Team for making this possible. Great Work!
Thanks for your information Sayed-Ibrahim-Hashimi. I have been searching for a solution for compatibility issue problem. You really helped me indirectly.
thank you Sayed