Rick Strahl's Weblog  

Wind, waves, code and everything in between...
.NET • C# • Markdown • WPF • All Things Web
Contact   •   Articles   •   Products   •   Support   •   Advertise
Sponsored by:
Markdown Monster - The Markdown Editor for Windows

A first look at ASP.NET 2.0 Web Projects


:P
On this page:

So I’m finally getting around to taking a look at the ASP.NET 2.0 Web Projects tonight. I’d been meaning to do this but was a little put off by the ‘pretty raw’ comments from a few people I trust. And no doubt this tool has some rough edges yet, but you can easily see how it works and where this is headed. Well, I’m in the process of consolidating all of my various notes and entries on compilation and deployment into an article and I figured I better take a look at this before putting this together.

 

The tool basically provides a project model that is very similar to VS.NET 2003 projects. You have a real project file (not a file based structure) that files have to be added to explicitly. Files aren’t picked up automatically based on the directory structure as is the case with the default ASP.NET projects. Instead you have manually add files to the project, which is like all other projects in VS.NET. The project has most of the project features you’d expect a VS.NET project to have including the Project property sheet and an MSBUILD File that backs it all. You can set compiler directives directly, the project can go under source control.

 

The other big win in my opinion is that once you start adding files to the project and you build it, it builds like it did in VS 2003: You build a single DLL that gets compiled and stored in the BIN directory. Which means in place compilation is back and you can copy files directly out of your project directory to the server without having ASPNET_COMPILER muck with your files and changing timestamps on you. Yay!!! 

 

In stock VS2005 Web Projects Web compile using ASPNET_COMPILER, into a separate directory copying all the files in your project to a new path. ASP.NET also creates one assembly per source file initially so there’s all sorts of disk trashing and individual process starts as the compiler fires up and compiles. No wonder that this is slow. With the new Web Projects everything compiles into a single assembly and it seems a lot faster. Ok I didn’t create any large projects yet and I can’t just import an existing project by copying files, but on first try with a few pages it looks great.


This also addresses another problem: Control and Page referencing. ASP.NET 2.0 by default creates individual assemblies of each control and page and there have been major issues in referencing other pages and User controls and master pages dynamically at runtime. Unless you explicitly import the Page/Control via the @Register directive in the page it can’t be referenced as a strong type. So the Web Projects sidesteps this issue by compiling every piece of code in the Web Project into a single assembly so everything can reference everything else in the same assembly without any issues.

 

This model generates a single assembly of all the source code in your project, but I’m not sure that it is going to be able to create a single assembly that also includes the generated ASPX code, so that like with a Precompiled Web you can deploy a single assembly (plus any reference assemblies) to run your app.

 

This model is very similar to VS2003, but there are a few improvements, most notably that it doesn’t use FrontPage extensions to connect to a Web, but rather uses raw HTTP connections and interaction with the local machine IIS installation to figure out the location of the project.

Not all good

Ok, so far so good. But now for the bad news: These projects use a different code generation scheme. Which means if you have existing ASP.NET 2.0 pages and control they won’t work as is. I have a fairly large ASP.NET 2.0 app that I have ported up from 1.1 and painstakingly updated to 2.0. I tried to import that into the new project, but it turns out that won’t work. It looks like from some of the support documentation and posts that this will somehow be supported in the full version but right now there’s no two-way back and forth support between a stock project and these Web projects.

 

Specifically Web Projects creates 3 files for each page: The ASPX page, a codebehind page with a partial class of your code and a designer page. If you’ve used WinForms in VS2005 then you know what this will look like. The designer.cs file basically contains all the control definitions and event hookups that in stock ASP.NET 2.0 pages are generated on the fly. The idea is that this tool doesn’t use ASPNET_COMPILER to do the dynamic code generation at compile time, but rather it uses the stock CSharp/VB compilers to compile an already fully generated page class. It’s the same stuff that used to be generated into the actual source file in VS2003 in the Web Designer Generated section of the page with InitializeComponent and OnInit() with the added benefit that partial classes allow separation of the file. This means we’re back to design time code generation…


The difference is that ‘normal’ ASP.NET pages in VS2005 generate the partial class that contains controls and event hookups dynamically at compile time based on the ASPX script page. In Web Projects, this generation is shifted to design time now. Actually – in this preview release – there’s no code generation at all – you have to do it yourself by adding control definition and event hookups manually into the designer source file. Ouch!

 

I’m assuming based on the comments in the designer page that the generation will happen automatically in the future. We’ll have to see how this works out. I’m a little worried about going back to design time generation and all that entails - keeping the designer and files in sync was the cause of much frustration in VS2003 after all and we can only hope that this tool does a better job of not mysteriously loosing event hookups and other declarative tags.

 

I hope the designer files can be generated at any time, so that you can drag and drop a file from disk that is from a stock 2.0 project and that it then automatically generates the designer file. This would make it possible to run pages either with the new projects or with stock projects which would just ignore the designer file. The key is really that the designer file must be easily creatable and be guaranteed to stay in sync unlike the VS2003 implementation <g>. I think the ASP.NET team is fully aware of this issue and I would expect this to be the case.

 

The other ‘issue’ with this model is that we loose a few cool features of the stock ASP.NET 2.0 model. Specifically you loose the partial compilation functionality for debugging and testing. One feature that I like a lot in ASP.NET 2.0 is the fact that you can debug a page, make a change to it and keep on running without recompiling the entire app. ASP.NET recompiles just that one assembly and so doesn’t need to restart the app entirely. No AppDomain restarts, no debugger hookup etc. That feature is gone with the Project Model. On the other hand compiles should be much faster and startup potentially isn’t that much slower than the simple restart. In my current setup debugging VS2003 apps is still faster even with a full recompile app restart than making a change and re-running the page in a sizable application.

 

So ultimately what we have here is a parallel development model to the stock ASP.NET 2.0 support in VS.NET. Assuming that this tool gets all the bells and whistles that we take for granted in the stock ASP.NET projects (View Code, View in Browser, hotkeys, Debug etc.) this option looks very promising.

 

It’s not clear at this point whether it will be easy to go back and forth with. I hope that you will be able to do this, but we’ll have to see how this turns out. But you have to make a choice one way or the other. I think for the way I like to work, this project model is a better fit even though you loose some of the simplicity of stock File Based Project model.

 

I also worry about the ‘after market’ issue. I ship a lot of projects and tools to customers and for download etc. If you really embrace this new model you are then requiring your customers to have this tool installed as well. Likely Microsoft will release this as an add-on unsupported tool and some customers may balk at that. Hopefully this will integrate into VS.NET natively with the next service pack.

 

If it does get integrated, I’m going to guess that this model will be widely embraced by developers in the know. Although a little more complex in concept the little bit of added complexity is far outweighed by the benefits: Single DLL output, In place compilation, page/control referencing, faster compiles and easier deployment…

Too many freaking choices?

I’m glad Microsoft is addressing these issues with tools, but I am getting a little concerned with the many, many options that are now available to deal with page compilation, project management and deployment.

 

Choices are good, but man, it’s getting downright confusing to pick the right mechanism for compilation, projects and deployment. You can work with CodeBehind, or in-place editing. Now add CodeBehind with the designer. For compilation you can use 1.1 style compilation and page set up or 2.0 style with partial classes. For deployment there are about 20 different ways to compile a project in combinations when you add in the Web Deployment Project tool.

 

If you’re the average Joe, who’s starting out with ASP.NET they are not going to know which approach is best for them. And to do it right you really need to use the new add-ons (Web Deployment Projects or now this Web Projects tool). I really hope Microsoft can integrate all of this functionality directly into VS.NET and Visual Web Builder rather than making these things add-ons.

 

For Compilation I’d like to see something similar to my compilation tool (in terms of UI and options) so you can see all of the options at a glance and you can experiment easily with them, which given the many options I think is important.

 

For the new Web Project, I think it would be nice if you could compile into a single assembly somehow, so that ASPX pages don’t need to be deployed at all. Right now Web Projects seems to mimic the ASP.NET 1.x model of compilation which still leaves the ASPX pages on the site and being dynamically compiled at runtime. If we’re already reworking this process, let’s go all the way and provide a mechanism to compile all that ASPX code into another or even the same assembly for packaging. That way you can upload 1 or 2 assemblies and be done with it without having to worry about keeping ASPX files in sync. The ASPX files can stay as placeholders for Authentication if Windows Auth is used. I think that single assembly compilation continues to be one of the most sought after goals and this provides another chance to provide it (the other being the Web Deployment projects).


The Voices of Reason


 

steve
December 28, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Your comprehensive article will be most welcome. When will MS ever learn?

I remember dumping the MS/Lattice C compiler in 1985 with it's arcane command-line flags, and buying Turbo Pascal 3.0, in which I hit 'R' for 'run'. It compiled, linked, and just freakin' ran.

Developers need to worry about their code, not how to compile.

Peter Bromberg
December 29, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Yup. When some enterprising developer writes a conversion app that will import any one of these arrangements and spit it all out perfectly as one of the others, they will have a product that I will buy...

To hear details about why technology is too complicated, press "3".

steve
December 29, 2005

# re: A first look at ASP.NET 2.0 Web Projects

One comment about deploying aspx pages, or not: have had projects in the past where it was necessary to give technical end-users the abiltiy to change the content on a page -- the page had no code logic (except perhaps for a user control) and was there just to display text.

Dreamweaver was used as the content editor, and there were some tags in the page that demarked what was editable and what was not. Thus, every time they wanted to change something a recompile was not needed.

Rick Strahl
December 29, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Steve, I agree on deployment of ASPX pages - it makes sense in a lot of scenarios. But not all applicatons are going to need that and in those scenarios it will be much easier to have just a single directory of files to deploy instead of keeping track which files have changed <g>...

I was kind of in that camp to until I played around with the all precompile options in the Web Deployment projects. It makes life a lot easier to have one file to deploy even if you're making a change to a single ASPX file. In most cases (other than the new project model) you still need to run the ASP.NET compiler anyway and fire up an FTP client to get it up to the server. Sending a bigger file is not a huge issue at that point.

Steve
December 29, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Rick, for deployment it does make it simpler for me too. It's just that we had a boss who was adamant about not having the IT department involved for minor content changes.

One day you need to do a paper on how you are so productive living in Maui...

scottgu
December 29, 2005

# re: A first look at ASP.NET 2.0 Web Projects

The .vb/.cs code-behind files and .aspx files are identical between the web-site and web-application project models. So from a learning/coding perspective -- you should find that there is one set of concepts/APIs/code to write.

The one difference syntactically is that the .aspx file with the web-site project has a "codefile=" attribute that points to the code-behind file, whereas the web-application project has a "codebehind=" attribute. If the code-file attribute is set, then ASP.NET and VS 2005 will dynamically generate the partial class containing the .aspx generation with the code-behind file (and not persist it in the project). If you have code-behind= set, then ASP.NET will rely on VS 2005 to have generated the other half of your code-behind partial class for you and explictly added it into the project. The parser is the same for both cases - so this should avoid some of the issue that VS 2003 web projects have today where VS 2003 gets confused about the markup and generates the wrong code-spit.

To answer a question from Rick's post above -- the next refresh of the web application project download will generate and maintain the .designer.cs/.vb file for you (this contains the partial class generated code). This will not only make life easier, but also make moving code-behind from a web-site project to a web-application project easy.

Hope this helps,

Scott

Rick Strahl
December 30, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Thanks for the clarification Scott. I think to really see this work kinda requires this next update. <g>

Is there going to be any sort of Wizard that can convert pages from one project type to the other? It sounds like there are going to need to be changes made to each page, so this seems like a crucial thing to do.

Also any comment on the one file compilation for both ASPX and and code behind files? Your previous post hints at integration with Web Deployment projects, but it doesn't really clarify what this might do for us since you obviously can't run ASPNET_COMPILER against these new projects <g>...



Gabe
December 30, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Scott, one more question. Like Rick, I have "painstakingly" converted a large 1.1 app to the 2.0 model. I am looking forward to the "re-embrassing" the project model with this add-on. My questions is, will this model still require special directories like App_code and App_GlobalResources? My guess is no for class files, but what about resource files?

Rick Strahl
December 30, 2005

# re: A first look at ASP.NET 2.0 Web Projects

Gabe, I don't think so. The new project file work like any other VS project so anything in there gets compiled. The main reason for APP_CODE was so that files that need to be globally accessible ended up in a common, known assembly in the stock model. With the new stuff that's not necessary since everything goes into a single assembly.

Bob Archer
January 03, 2006

# re: A first look at ASP.NET 2.0 Web Projects

Rick,

Good blog post. I posted some of the same issues as a comment to Scott's orginal blog post on the new project type, but they never showed up.

As far as the *.designer.* files are concerned, WHY?, WHY?, WHY? create them at design time. I think they should be created at compile time and included in the DLL rather than me having to worry about them getting out of sync and also source controlling them.

I don't know why this new "web-application" project type can't be more like the web-site type now with the following differences:

1. Only files in the project are included in a build rather than all files in the folder.

2. Rather than have an App_Code folder, there can be a build type for shared files. (This will be used with item 3 below).

3. In debug mode the system acts and builds like the web-site project, using seperate DLL's for each page and a single DLL for all the "shared" files tagged (see item 2.).

4. In release mode builds are compiled to a single DLL a la VS 2003, however the .designer.* part is also genned and included in the DLL.

Comments?

BOb


scottgu
January 04, 2006

# re: A first look at ASP.NET 2.0 Web Projects

Sorry for the delay in getting back to these answers -- I didn't realize there were more posts on this thread after my post above.

To answer a few of them:

Gabe: The new project model doesn't require App_Code -- you can instead store classes in whatever directory you'd like. You can optionally use App_GlobalResources for defined global resources for your pages -- or alternatively just add the .resx files to your code-behind assembly (similar to VS 2003).

Rick: Moving between the web-site model to the web application model is fairly straight forward (and we will probably have a wizard to help automate it).

You *will* be able to use web deployment projects with this new project model option with its next refresh. Note that the aspnet_compiler.exe can be used against web application projects already (as can aspnet_merge). It won't be used to compile the code-behind (since this is done by the web application project model), but it can be used to pre-compile the html and server controls out of the .aspx pages.

Bob: I actually posted your comment here a few weeks ago: http://weblogs.asp.net/scottgu/archive/2005/12/18/433374.aspx#433452 and responded to it here: http://weblogs.asp.net/scottgu/archive/2005/12/16/433374.aspx#433465 (there were a lot of comments on this particular post, which is probably why you missed it).

Hope this helps,

Scott

Bob Archer
January 06, 2006

# re: A first look at ASP.NET 2.0 Web Projects

Scott,

Thanks, I didn't see that response.

Pieter Siegers
January 19, 2006

# re: A first look at ASP.NET 2.0 Web Projects

Hi Rick,

I hjaven't read the comments but did you know that when you create a new project type ASP.NET Web Application and later on try it to open using normal Open | Web site the VS.NET 2005 Upgrade Wizard appears?

I know I should use Open | Project but hey this shouldn't happen IMO.

Cheers,
Pieter

Rick Strahl
January 19, 2006

# re: A first look at ASP.NET 2.0 Web Projects

No I haven't tried that but that would make sense. ScottGu mentioned there will be wizards that can shuffle these projects between the two types in the future.

Joseph Baggett
February 15, 2008

# re: A first look at ASP.NET 2.0 Web Projects

I found a way to have the designer generate the code. When you are on your source code, you can push F7. I have found this works most of the time, but not all the time. Hope this helps others from not having to type up everything in the designer.

Joseph Baggett

West Wind  © Rick Strahl, West Wind Technologies, 2005 - 2024