Hack the Build: Use Whidbey Beta2 to target .NET Runtime 1.1

Hack the Build: Use Whidbey Beta2 to target .NET Runtime 1.1

Rate This

Jomo Fisher – A while back, I posted a sample that showed how to target the .NET 1.1 runtime (the version that came with Visual Studio .NET 2003 also known as Everett) with MSBuild. Now Beta 2 has rolled around and I can see that there have been enough changes to MSBuild to warrant an entire rewrite of that original sample.

I’ll get into the details of how it all works down below, but right now let’s just get it working on your machine. Here are the steps:

(1)   Copy this MSBuild targets file to “C:\program files\msbuild\CrossCompile.CSharp.targets

(2)   Create a new C# project somewhere called MyApp.

(3)   Use notepad to edit MyApp.csproj. Replace the entire <Import> tag with

  <Import Project="$(MSBuildExtensionsPath)\CrossCompile.CSharp.targets" />

(4)   When prompted, reload the project. You’ll have to answer a security dialog.

(5)   In VS, click the drop-down that says ‘Any CPU’ and select ‘Configuration Manager’

(6)   Under Active Solution Platform, select <New…>

(7)   Select ‘.NET 1.1’ (pretty cool, eh?) and press OK.

(8)   Build and notice error about System.Collections.Generic. This means its working because generics aren’t supported in 1.1.

(9)   Open Program.cs and delete the line:

using System.Collections.Generic;

     And rebuild.

That’s it, its working.

As with the last sample I posted on this, I expect that only basic scenarios will work here. If you run into a problem, drop me a note. If I see a quick solution I'll post it. Otherwise, I can still publish those limitations here so that other people can learn from your experience.

What’s New?

There are some differences between this version and the prior sample I published that show off some nice new features in MSBuild for Beta2:

  • This version shows how to add entirely new Platforms for VS to pick up. See the $(AvailablePlatforms) property in CrossCompile.CSharp.Targets. You could, pretty easily, add other targets from .NET 1.0 or any other tool that is roughly command-line interchangeable with CSC.EXE.
  • The reference resolution logic in this version is far more robust. Many more scenarios should work now, including references to third-party assemblies as well as project-to-project references. (Though you still can't reference 2.0-compiled assemblies into 1.1 projects--this is a limitation built into the CLR itself).
  • We’ve added a new built in property called $(MSBuildExtensionsPath) which is defined to be like “C:\Program Files\MSBuild”. This is a well-known spot where people can dump their custom targets files. This saves you from having to hard-code a path in your project or template.
  • Targets can now be entirely overridden. The GetFrameworkPaths targets from Microsoft.Common.Targets is overridden in CrossCompile.CSharp.Targets so that an alternate directory for target framework directory can be injected.
  • This version doesn’t build 2.0 and 1.1 at the same time. This is nicer, I think, because otherwise you see duplicate errors when you build.

Moving On

At the end of this month I'm moving from the MSBuild team (5th floor, building 41 in Redmond) to the C# team (1st floor, building 41 in Redmond). Working on MSBuild has been a blast and I intend to keep on blogging about it if I think I having something of value to say. After a while, I hope to have something useful to say about C# too. I think "Hack the Build" still fits, so I'll keep the name.

This posting is provided "AS IS" with no warranties, and confers no rights.

Leave a Comment
  • Please add 3 and 5 and type the answer here:
  • Post
  • Blog link of the week 16
  • I think there's a bug in the targets file. I think this line (in the PropertyGroup)

    <TargetFrameworkVersion>v1.0</TargetFrameworkVersion>

    Should read like this:

    <TargetFrameworkVersion>v1.1</TargetFrameworkVersion>

    I'm not 100% sure. You'd know better than I do.
  • Good eye for spotting that TargetFrameworkVersion issue. However (and unfortunately) the code will only work the way it is now. This property is only used to remove references to warnings that only exist for CSC 2.0. See mention of this property in Microsoft.CSharp.targets.
    We hope to fix this issue in Microsoft.CSharp.targets before we ship.

    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Jomo Fisher has posted an update of his build targets for VS2005 beta 2, with these, you can build apps...
  • Since the release of&amp;nbsp;beta2 of Visual Studio 2005 I have been looking for a way to code in beta2...
  • Since the release of&amp;nbsp;beta2 of Visual Studio 2005 I have been looking for a way to code in beta2...
  • Thanks for the info! Sorry to see you leave the MSBuild team
  • Very cool. Perhaps it will be possible to add Mono and IKVM targets as well!
  • I've tried using this in Express Beta 2, but am getting an error.

    When I do a build, I get the following 1 warning and 1 error:

    Warning 1 The "CFResGen" task could not be loaded from the assembly C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\\Microsoft.CompactFramework.Build.Tasks.dll. Could not load file or assembly 'file:///C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\Microsoft.CompactFramework.Build.Tasks.dll' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, and that the assembly and all its dependencies are available. C:\Program Files\MSBuild\CrossCompile.CSharp.targets 0 0
    Error 2 The "CFResGen" task was not found. Check the following: 1.) The name of the task in the project file is the same as the name of the task class. 2.) The task class is "public" and implements the Microsoft.Build.Framework.ITask interface. 3.) The task is correctly declared with <UsingTask> in the project file, or in the *.tasks files located in the "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215\" directory. C:\Program Files\MSBuild\CrossCompile.CSharp.targets 113 3
  • Replacing occurances of "CFResGen" with just plain "ResGen" seems to do the trick for me. I assume "CF" refers to the compact framework, which isn't part of Express, correct?

  • Is it possible? Yes, it is possible, though not without a little finesse.
    &amp;nbsp;
    Jomo Fisher has a...
Page 1 of 8 (107 items) 12345»