Hack the Build: Targetting .NET Runtime 1.1 Step-by-Step
Note: This article is about targetting CLR version 1.1 with Whidbey Beta1. If you're interested in Beta2 see this article.
Jomo Fisher--MSBuild doesn't ship with a way to target CLR version 1.1. I discussed the reasons for this in a prior blog entry and I even said that I respected the decision given our resource limitations. On the other hand, respecting something and living with it is not the same thing so I decided to see exactly what it would take to target an older CLR.
My criteria were modest:
- I want reuse most of the existing build logic that ships with MSBuild. After all, this blog is about hacking the build, and throwing everything away and starting over didn’t seem in the spirit of things. (Plus it would be hard and I’m lazy).
- I wanted to build both Whidbey and CLR 1.1 binaries at the same time (in the same build gesture).
- I wanted to be able to compile at least minimal console applications, window applications and libraries.
- I wanted to keep Intellisense working and reflecting latest Whidbey libraries.
- I wanted to be able to call library code in other projects in the solution.
- I was willing to live with only C# support (at least for now).
- I didn't care too much about optimal rebuild or clean support (at least for now).
What I ended up is a .targets file that meets my goals and that you can use as a sample for how to target multiple platforms with MSBuild. Here are the steps for Whidbey Beta 1:
(1) Copy this sample into a file called C:\MyTargets\CSharp.SideBySide.Targets
(2) Create a new C# console application called MyApp.
(3) Build and see that there are no errors or warnings.
(4) Open up MyApp.csproj in notepad and replace the import tag near the bottom with,
<Import Project=" C:\MyTargets\CSharp.SideBySide.Targets" />
(5) Save and exit from notepad.
(6) Return to VS and press “Reload” when prompted.
(7) Now “Rebuild” the console application.
At this point, if the build fails with a message like,
Properties\Settings.cs(13,9): error CS1518: Expected class, delegate, enum, interface, or struct
Then it’s working. This error is because the CLR 1.1 C# compiler doesn’t support partial classes. To get past this, you’ll need to delete the Settings.cs file. In the Solution Explorer click “Show All Files”. Now, in the Solution explorer you should see an entry called Settings.settings. Delete it and rebuild the project again.
At this point, the build should fail again with a message like,
Program.cs(4,26): error CS0234: The type or namespace name 'Generic' does not exist in the class or namespace 'System.Collections' (are you missing an assembly reference?)
This is because the old compiler didn’t support generics. You’ll need to delete this line,
using System.Collections.Generic;
from Program.cs and then build again. (As you can see, there are plenty of neat new features in the new compiler that you won't be able to use if you want to target the older framework.)
This latest build should succeed, and you should now have a bin directory that looks like this (in part):
bin\Debug\ConsoleApplication1.exe
bin\Debug(1.1)\ConsoleApplication1.exe
The first is the plain old Whidbey application. The second is a version that will run under the CLR version 1.1.
Please keep in mind that only the very basic scenarios have a chance of working. For example, I’m pretty confident that COM references are completely broken. If you try these targets out, let me know what you have problems with. If I can see a cheap, hack-the-build-worthy solution I’ll update the sample as I have the time.
Whidbey still won't ship with a way to target the 1.1 CLR but at least now there's starting point for doing it yourself.
In future entries, I will take apart the sample and explain how the various hacks pieces work.
[Update December 16, 2004 --Jomo Fisher
Check out another community effort to target the 1.1 FX.
https://mark.michaelis.net/Blog/PermaLink.aspx?guid=a2aa1af7-e71e-4296-81fe-7bcecbb7a9cd]
[Update October 8, 2004 --Jomo Fisher
It looks like there's a chance that target names with dots in them will be illegal starting with Beta2. I've updated the sample, but if you're using the prior version, you may want to get the latest to avoid being broken down the road.]
[Update October 5, 2004 --
Jomo Fisher
Looks like there's a similar effort going on at Test Driven .NET. This one actually creates a replacement for MSBuild.exe. Very cool. Here's the link:
https://weblogs.asp.net/nunitaddin/archive/2004/10/05/238009.aspx]
[Update October 3, 2004 --Jomo Fisher
What a difference a day makes. Robert McClaws saw my Hack the Build: Targetting .NET Runtime 1.1 Step-by-Step article from Friday and identified several ways to make it better. He wanted to target the 1.0 CLR, he wanted VB support, he wanted more flexible choices over where outputs go. In other words, he wanted the build that *he* wanted, and that's what MSBuild is all about.
From his posting,
"So I spent the past 24 hours (practically straight) working on making everything work the way I wanted. The result is the MSBuild Compatibility Toolkit, a clean, standardized system for extending .NET Framework compilation support, with or without Visual Studio 2005."
I haven't looked at his stuff, but it looks like it has a nice installer MSI and (if my reading of his post is correct) he's made templates for creating new projects.
You can check his stuff out here.]
This posting is provided "AS IS" with no warranties, and confers no rights.
Comments
Anonymous
October 03, 2004
There is an open suggestion with 61 votes, currently all-time #11, on this issue:
http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=15986521-ee6a-4397-8937-1b9cee7f2cf1
Given the amount of interest in this, I would strongly suggest that the MSBuild team re-think their priorities. One other major reason is VSTS support. If companies are to migrate over to VSTS, using VS2003 is not even an option as the client requires 2005.Anonymous
October 09, 2004
TrackBack From:http://www.cnblogs.com/ccboy/archive/2004/10/09/50326.aspxAnonymous
October 17, 2004
The comment has been removedAnonymous
October 17, 2004
I made mistake - I was referencing 2.0 assembly - that's why it was not included.Anonymous
October 17, 2004
Glad you liked! I was hoping you wouldn't be mad. Thanks for the "dots" update. I'll be looking at the changes in the CTP that goes out next week and modifying accordingly. Any chance that you know how to programmatically access the Project's targets references?Anonymous
January 01, 2005
Tiernans Blog » Target .NET 1.1 with MSBuildAnonymous
April 06, 2005
I'm currently trying to find a way of building .NET apps for .NET 1.1 using MSBuild.&nbsp; Not entirely...Anonymous
April 22, 2005
Jomo Fisher – A while back, I posted a sample that showed how to target the .NET 1.1 runtime with MSBuild....Anonymous
January 03, 2006
may i Targetting .NET Runtime 1.1 for c++ managed extentions?
thanksAnonymous
February 08, 2006
The following is my official VSTS jumpstart kit.&nbsp; I will maintain this post entry going forward....Anonymous
February 08, 2006
Internet Links
Visual Studio Team System Home
Getting Started with Team Foundation
MSDN Technical...Anonymous
April 19, 2006
One of the FAQs in Team Foundation forums have been on "how to build .NET 1.1 application using Team...Anonymous
October 25, 2006
Internet Links Visual Studio Team System Home Getting Started with Team Foundation MSDN Technical ForumsAnonymous
October 25, 2006
The following are some different resources to either convert your Visual Studio 2002/2003 projects toAnonymous
December 11, 2006
Excellent browsing have the toAnonymous
December 13, 2006
Excellent browsing have the toAnonymous
December 21, 2006
Very interesting.,Very interesting.Anonymous
December 23, 2006
Very interesting.,Very interesting.Anonymous
February 12, 2007
Hi! <a href= thanks for sharing ></a> [url=thanks for sharing][/url]Anonymous
February 12, 2007
Hi! <a href= thanks for sharing ></a> [url=thanks for sharing][/url]Anonymous
February 12, 2007
Hi! <a href= thanks for sharing ></a> [url=thanks for sharing][/url]Anonymous
February 15, 2007
Hi! <a href= b52156c8aac1434d38838ef84dfbd701 ></a> [url=b52156c8aac1434d38838ef84dfbd701 ][/url]Anonymous
February 15, 2007
Hi! <a href= 459320b57da587f577b1d5efbb5947c8 ></a> [url=459320b57da587f577b1d5efbb5947c8 ][/url]Anonymous
August 09, 2007
I intended to post about this a couple of months ago and am finally getting around to it. Good news thoughAnonymous
August 09, 2007
I intended to post about this a couple of months ago and am finally getting around to it. Good news thoughAnonymous
August 09, 2007
I intended to post about this a couple of months ago and am finally getting around to it. ...Anonymous
August 11, 2007
I intended to post about this a couple of months ago and am finally getting around to it. ...Anonymous
August 22, 2008
I was trying to write that post for so long that I've started worry that there will be new versionAnonymous
August 22, 2008
I was trying to write that post for so long that I've started worry that there will be new version