Code that compiles under both ASP.NET 1.1 and 2.0?

W

wizofaus

Has anyone successfully managed to work out how to get ASP pages to
compile under both 1.1 and 2.0? Basically I'm in the final stages
before deploying a version of an application that will be using 1.1,
and still making occasional fixes, but I'm also trying to move over
to .NET 2.0 for the next version. The biggest problem I've hit is the
new compilation models. From what I've read, .NET 2.0 is supposed be
able to support the old "codebehind" compilation model for .NET 1.1
that doesn't require partial classes etc., but the only way I've been
able to get it to work is to change the .aspx @page directive to use
"Src=" instead of "CodeBehind=". Without this I get a "Could not load
type 'xxx'" error for every page using Codebehind. But doing this
causes it fail with strange runtime errors under .NET 1.1 (mainly to
do with types being defined in multiple places).
The other alternative was use wrap the "partial" keyword, plus the
page control variable definitions not needed under .NET 2.0 in an #if,
and have both the "Codebehind" AND "Codefile" directives in the ASPX
pages - .NET 2.0 appears to ignore the former, and .NET 1.1 the
latter, so I believe this will actually work, but I'm not 100%
confident by any means, and it sure looks ugly having code like:

public
#if NET20
partial
#endif
class MyPage : System.Web.UI.Page
{
#if !NET20
public TextBox TextBox1;
public TextBox TextBox2;
#endif
}

all over the place!

Then there's the issue of code that needs to be in the App_Code
directory...although I can deal with that via the Source Control
system relatively easily.

I expect to be fixing bugs in the 1.1 version for at least a few weeks
yet, and having to continally manually apply them to the 2.0 version
seems theoretically more painful than trying to stick with a single
code version (note that I'm not planning on making functionality
changes to the 2.0 version for a while, otherwise obviously I would
need two code branches), but I suspect that MS haven't exactly made
this easy to achieve, for whatever reason.
 
G

Guest

If you want more interoperability between 1.1 and 2.O, use the Web
Application Project model instead of the original WebSite model in ASP.NET
2.0.
99% of 1.1 code WILL compile just fine in .NET 2.0.
Peter
 
W

wizofaus

If you want more interoperability between 1.1 and 2.O, use the Web
Application Project model instead of the original WebSite model in ASP.NET
2.0.
99% of 1.1 code WILL compile just fine in .NET 2.0.
Peter
Sounds exactly like what I want. I'm just installing SP1 now
actually, which apparently includes it. I take it there are no real
disadvantages to using this, given I'm quite happy with the .NET 1.1
compilation model for my particular project?
 
W

wizofaus

Sounds exactly like what I want. I'm just installing SP1 now
actually, which apparently includes it. I take it there are no real
disadvantages to using this, given I'm quite happy with the .NET 1.1
compilation model for my particular project?

I did hit two minor issues...one was that it wasn't copying my CSS
files to the deployment location (I had to mark them explicitly to be
copied), and the other was that when debugging under VS.NET 2005 it
apparently always uses NTLM authentication, which was causing problems
with my own authentication code (I was prematurely checking for the
LOGON_USER server variable), but both problems were easily fixable,
and it all seems to be working fine. Pleasantly surprised that MS
apparently saw the need to make the upgrade path from 2003 somewhat
simpler!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top