Freigeben über


SYSK 273: How to use the latest version of Visual Studio and build your project targeting earlier version of .NET framework

First, little explanation for what prompted me to write this post…

 

It came to my attention that some teams dedicate a build server for each Visual Studio/.NET framework combination, i.e. they don’t upgrade Visual Studio (or the build tools) because they need to build certain projects (developed using the latest version of VS but utilizing only backward compatible features) to run on current and previous versions of the .NET runtime… So, they build the source on different build servers targeting required runtime.

 

The msbuild process is so flexible, that this is absolutely not necessary! Below are simple steps you can implement and have ability to choose your target runtime at build time... The example below adds ability to target .NET 1.1.4322 runtime, but you can use same process to target other runtimes…

 

1. On VisualStudio toolbar click ‘Solution Configuration’ dropdown list (the one with Debug, Release, Configuration Manager... items, usually found right after the 'Start Debugging' icon), and select 'Configuration Manager...' option.

2. Click 'Active Solution Configuration' dropdown list and click <New...> item

3. In the 'Name' textbox, type in 'Debug .NET 1.1'

4. In the 'Copy settings from' dropdown list, select 'Debug' item and click Ok

5. Repeat steps 2 through 4 for Release .NET 1.1 build

6. Close solution

7. Open your project(s) file (.csproj) using a text editor (e.g. Notepad)

8. Towards the end of the file, right before

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

line, add the following section:

<PropertyGroup Condition=" '$(Configuration)' == 'Debug .NET 1.1' OR '$(Configuration)' == 'Release .NET 1.1' " >

<TargetFrameworkVersion>v1.1</TargetFrameworkVersion>

    <TargetFrameworkDirectory>c:\windows\Microsoft.NET\Framework\v1.1.4322</TargetFrameworkDirectory>

    <ReferencePath>c:\windows\Microsoft.NET\Framework\v1.1.4322</ReferencePath>

</PropertyGroup>

9. Reopen your solution. Now, you should have an option to compile for current .NET version (debug or release) or .NET 1.1 by selecting your choice in the Solution Configuration dropdown list. To see what versions of referenced components were loaded, you can use the following code:

 

System.Text.StringBuilder sb = new System.Text.StringBuilder();

foreach (System.Reflection.AssemblyName n in System.Reflection.Assembly.GetExecutingAssembly().GetReferencedAssemblies())

{

    sb.AppendLine(n.FullName);

}

MessageBox.Show(sb.ToString());

Comments

  • Anonymous
    January 24, 2007
    PingBack from http://www.wackylabs.net/2007/01/lots-of-something-you-should-know/

  • Anonymous
    January 24, 2007
    What about MFC?

  • Anonymous
    January 24, 2007
    Thank you!  This is the easiest explanation for this that I've seen. I don't touch any of my .NET 1.1 projects any more because I don't have VS 2003 installed.  I've also been reluctant to install .NET 3.0 for the same reason.

  • Anonymous
    January 24, 2007
    Note that .NET 3.0 doesn't replace most of the 2.0 assemblies...  See for yourself:  create a WPF project, build it and open manifest with ildasm...

  • Anonymous
    January 31, 2007
    I think the "||" should be "Or". http://msdn2.microsoft.com/en-us/library/7szfhaft.aspx

  • Anonymous
    January 31, 2007
    You're absolutely correct.  Fixed.

  • Anonymous
    February 16, 2007
    If this title is totally confusing to you, you may want to check out one of my previous posts XBAP Introduction