Thursday, November 04, 2004

ASP.NET Applications without Web Projects

Super handy link: this article shows you how to hack Visual Studio's config files and projects so that you can create web projects as class libraries. Although Fritz Onion gives a pretty good overview, you still need to rummage through the config files. For your convienence, here is the contents of my config file: C:\Program Files\Microsoft Visual Studio .NET 2003\VC#\ CSharpProjectItems\LocalProjectItems:
UI{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#233610
Code{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#233820
Data{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#233430
Web{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#233740
Utility{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#233550
Resources{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#236260
..\CSharpAddWebFormWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#223610#2263{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45340WebForm.aspx
..\CSharpAddWebServiceWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#224320#2266{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45210Service.asmx
..\CSharpAddMobileWebFormWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#239825#2399{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45710MobileWebForm.aspx
..\CSharpAddWinFormWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#223710#2264{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45350Form.cs
..\CSharpAddClassWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#224520#2262{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45150Class.cs
..\CSharpAddComponentWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#224630#2265{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45170Component.cs
..\CSharpAddWebDataForm.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#238045#2381{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45590DataForm.aspx
..\CSharpAddUserControlWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#229540#2296{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45320UserControl.cs
..\CSharpAddWinDataForm.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#238045#2382{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45600DataForm.cs
..\CSharpAddDataSet.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#227750#2278{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45220Dataset.xsd
..\NewXMLPage.xml{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#224460#2279{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45240XMLFile.xml
..\CSharpAddXMLSchema.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#227570#2276{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45230XMLSchema.xsd
..\NewCSharpFile.cs{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#226180#2267{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45160CodeFile.cs
..\CSharpAddCustomControlWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#229390#2294{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45270CustomControl.cs
..\NewHTMPage.htm{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2042100#2280{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45280HTMLPage.htm
..\CSFormInheritanceWizard.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2341110#2343{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4531 Form.cs
..\CSharpAddWebControlWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2297120#2298{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45330WebCustomControl.cs
..\CSControlInheritanceWizard.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2342130#2344{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4530 UserControl.cs
..\CSharpAddWinServiceWiz.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2291140#2292{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45200Service.cs
..\CSharpAddWebUserControl.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#237855#2379{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45580WebUserControl.ascx
..\CSharpAddMobileWebUserControl.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#240056#2401{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45720MobileWebUserControl.ascx
..\StaticDisco.disco{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2393155#2394{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45250Disco.disco
..\CSharpAddGlobalASAX.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2304160#2305{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45428192Global.asax
..\CSharpAddWebConfig.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2312170#2313{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45458192Web.config
..\TextFile.txt{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2316150#2317{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45360TextFile.txt
..\Frameset.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2241160#2284{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45410Frameset.htm
..\XSLTFile.xslt{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2356170#2357{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4566 XSLTFile.xslt
..\StyleSheet.css{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2314180#2315{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45440StyleSheet.css
..\NewInstaller.vsz{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2269190#2270{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45180Installer.cs
..\Bitmap.bmp{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2384200#2385{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4562 Bitmap.bmp
..\Cursor.cur{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2386210#2387{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4563 Cursor.cur
..\Icon.ico{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2388220#2389{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4564 Icon.ico
..\Resource.resx{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2390230#2391{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}4565 Resource.resx
..\JScript.js{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2306240#2307{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45570JScript.js
..\VBScript.vbs{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2308250#2309{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45370VBScript.vbs
..\WindowsScriptHost.wsf{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2310260#2311{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}45380WinScript.wsf
..\app.config{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}#2403261#2404{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}46000App.config
Once you've made this hack, you'll be able to add webforms (and other web project items) to your class library. I find it's very useful to configure your new hybrid projects this way:
  1. Create a "Web" folder in your project
  2. Configure the Output Path of your project to build to "Web\bin"
  3. In the debug settings, set Enable ASP.NET Debugging to "True"
  4. Change the Debug Mode of the project to "URL"
  5. Set the Start URL to the name of the local IIS site that this code will execute under.
  6. Add System.Web.dll as a reference to your project.
  7. Create the new site in IIS.

Enjoy!

I've got a few other Visual Studio tweaks that I hope to post soon.

1 comment:

  1. Hi Bryan! Excellent Blog! It looks like we have similar interests...

    By the way, I'll be moving to Canada in a few months and I'd like to know more about the IT market in your country, may be you can help me... Could I send you a mail?

    Tks!!
    guillermo.ziegler@gmail.com

    ReplyDelete