|
|
These blog entries are written by industry experts and leaders. We consider this content to be a good read for any software developer or web technologist.
June 2007 - Posts
-
It's common behavior in the technology arena to hold on and wait for the next big thing. Sometimes we wait for bug fixes. Sometimes we wait for new features. It's not just software – I've waited for phones and TVs because I know the next generation will be so much better.
Have you ever picked up a piece of hardware or software and said, "this is perfect - I can't imagine anyone ever making this better?"
If so - how long did that feeling last?

|
-
I've been thinking about getting a MySpace page, but first I need a good design.
What do y'all think of this?
Define: Web 2.0. It's about me, me, and me.

|
-
Three Windows Mobile developers, Mort, Elvis, and Einstein, are sitting at the lunch table when their project manager bursts into the room.
PM: "Guys, I have some good news and some bad news."
Mort: "Tell us the good news first!"
Elvis: "Wait! I need to grab my laptop and take copious notes."
Einstein: "I have a theory about what you are going to tell us."
PM: "Be quiet and listen. The good news is that we bought iPhones for all the software developers".
Mort: "iPhones? But the product only targets Smartphones!"
Elvis: "Cool! Where is the SDK?"
Einstein: "You should've waited for an updated iPhone that includes GPS!"
PM: "The bad news is your iPhone is also your severance package. We've just moved all product development work overseas."

|
-
One of my first evaluated public speaking events was a disaster.
In high school, my teacher filled a basket with index cards. Each card had a "topic" printed on it. One by one, we had to go to the front of the room and pick a random card from the basket. We then had 60 seconds to prepare a 5-minute presentation on the topic we selected.
When it was my turn, I went to the front of the room and picked out a card. I looked, and my card said, "Break on through to the other side". I put the card in my pocket.
An abbreviated version of the next 60 seconds inside my head went something like this:
What does he expect from this? A motivational speech? I can't give a motivational speech! What are we suppose to break through? School? What's on the other side of school? This is terrible. I don't know what to talk about. I should say I'm going to the bathroom and pull the fire alarm.
Wait - this is a Door's song. Jack likes the Doors. I remember seeing another song called "Peace Frog". What a strange name for a song. "Peace Frog". Frogs eat flies.
Is my fly open? No.
If my fly was open in front of class, Melanie Weigel would be laughing and telling the whole school. She's such a drama queen. One day I'm going to fill her locker with shaving cream – just to see the scene she creates.
Flys.
Frogs.
Frogs are green.
Kermit the frog is green.
I loved the Muppet show. Especially those two old guys sitting in the balcony, razzing on everyone. I wonder if the show is ..."
Ding!
With no escape in sight, I put on my bravest face and stood behind a little podium at the front of class. Having completely forgotten my original topic, I proceeded to ramble for 5 minutes about characters on the Muppet show. You can't go wrong talking about Muppets. Everyone loves Muppets!
I could tell by my teacher's expression he wasn't loving Muppets. He asked me what was printed on my card. When I pulled out my card and announced my topic, there was about 10 seconds of dead silence. Everyone was trying to figure out how I went from "Break on through to the other side" to a television show about hand puppets named Miss Piggy and Dr. Bunson Honeydew.
Grade: 2/10.
I've worked really hard over the years to get better, and stay on topic.

|
-
I decided to try out Twitter, you can find me here. Oh yeah, you can find me on Facebook as well over here. And linkedin over here. Add me to google talk (jamesavery AT gmail) too if you use it (I am trying to move off MSN). When is someone going to make a social network for social networks to hang out on? -James 
|
-
I am done with the project I have been working on for almost 2 years now. To say we had challenges on the project would be an understatement, if you made it Day of .NET or the Dayton User Group you might have seen my presentation where I fill an hour and a half with all of the different problems we had. I am going to turn that presentation into a series of blog posts, hopefully starting with one this weekend. Yesterday was a fitting end to the project, after leaving the client for the last time I high-tailed it up to Columbus to see Wolfmother with Dave Donaldson (the man who recommended me and brought me onto this project). I really feel quite liberated now that I don't have a job and I am moving to Raleigh in about a week. I think over the past two years I haven't blogged about alot of things because I was worried about people at the client reading it (more on that later) but now that I am gone I feel I can really start blogging again. -James 
|
-
Last month I started a blog post series covering LINQ to SQL. LINQ to SQL is a built-in O/RM (object relational mapping) framework that ships in the .NET Framework 3.5 release, and which enables you to easily model relational databases using .NET classes. You can then use LINQ expressions to query the database with them, as well as update/insert/delete data from it. Below are the first two parts of my LINQ to SQL series: In today's blog post I'll be going into more detail on how to use the data model we created in the Part 2 post, and show how to use it to query data within an ASP.NET project. Northwind Database Modeled using LINQ to SQL In Part 2 of this series I walked through how to create a LINQ to SQL class model using the LINQ to SQL designer that is built-into VS 2008. Below is the class model that we created for the Northwind sample database: Retrieving Products Once we have defined our data model classes above, we can easily query and retrieve data from our database. LINQ to SQL enables you to do this by writing LINQ syntax queries against the NorthwindDataContext class that we created using the LINQ to SQL designer above. For example, to retrieve and iterate over a sequence of Product objects I could write code like below: In the query above I have used a "where" clause in my LINQ syntax query to only return those products within a specific category. I am using the CategoryID of the Product to perform the filter. One of the nice things above LINQ to SQL is that I have a lot of flexibility in how I query my data, and I can take advantage of the associations I've setup when modeling my LINQ to SQL data classes to perform richer and more natural queries against the database. For example, I could modify the query to filter by the product's CategoryName instead of its CategoryID by writing my LINQ query like so: Notice above how I'm using the "Category" property that is on each of the Product objects to filter by the CategoryName of the Category that the Product belongs to. This property was automatically created for us by LINQ to SQL because we modeled the Category and Product classes as having a many to one relationship with each other in the database. For another simple example of using our data model's association relationships within queries, we could write the below LINQ query to retrieve only those products that have had 5 or more orders placed for them: Notice above how we are using the "OrderDetails" collection that LINQ to SQL has created for us on each Product class (because of the 1 to many relationship we modeled in the LINQ to SQL designer). Visualizing LINQ to SQL Queries in the Debugger Object relational mappers like LINQ to SQL handle automatically creating and executing the appropriate SQL code for you when you perform a query or update against their object model. One of the biggest concerns/fears that developers new to ORMs have is "but what SQL code is it actually executing?" One of the really nice things about LINQ to SQL is that it makes it super easy to see exactly what SQL code it is executing when you run your application within the debugger. Starting with Beta2 of Visual Studio 2008 you can use a new LINQ to SQL visualizer plug-in to easily see (and test out) any LINQ to SQL query expression. Simply set a breakpoint and then hover over a LINQ to SQL query and click the magnify glass to pull up its expression visualizer within the debugger: This will then bring up a dialog that shows you the exact SQL that LINQ to SQL will use when executing the query to retrieve the Product objects: If you press the "Execute" button within this dialog it will allow you to evaluate the SQL directly within the debugger and see the exact data results returned from the database: This obviously makes it super easy to see precisely what SQL query logic LINQ to SQL is doing for you. Note that you can optionally override the raw SQL that LINQ to SQL executes in cases where you want to change it - although in 98% of scenarios I think you'll find that the SQL code that LINQ to SQL executes is really, really good. Databinding LINQ to SQL Queries to ASP.NET Controls LINQ queries return results that implement the IEnumerable interface - which is also an interface that ASP.NET server controls support to databind object. What this means is that you can databind the results of any LINQ, LINQ to SQL, or LINQ to XML query to any ASP.NET control. For example, we could declare an <asp:gridview> control in a .aspx page like so: I could then databind the result of the LINQ to SQL query we wrote before to the GridView like so: This will then generate a page that looks like below: Shaping our Query Results Right now when we are evaluating our product query, we are retrieving by default all of the column data needed to populate the Product entity classes. For example, this query to retrieve products: Results in all of this data being returned: Often we only want to return a subset of the data about each product. We can use the new data shaping features that LINQ and the new C# and VB compilers support to indicate that we only want a subset of the data by modifying our LINQ to SQL query like so: This will result in only this data subset being returned from our database (as seen via our debug visualizer): What is cool about LINQ to SQL is that I can take full advantage of my data model class associations when shaping my data. This enables me to express really useful (and very efficient) data queries. For example, the below query retrieves the ID and Name from the Product entity, the total number of orders that have been made for the Product, and then sums up the total revenue value of each of the Product's orders: The expression to the right of the "Revenue" property above is an example of using the "Sum" extension method provided by LINQ. It takes a Lambda expression that returns the value of each product order item as an argument. LINQ to SQL is smart and is able to convert the above LINQ expression to the below SQL when it is evaluated (as seen via our debug visualizer): The above SQL causes all of the NumOrders and Revenue value computations to be done inside the SQL server, and results in only the below data being retrieved from the database (making it really fast): We can then databind the result sequence against our GridView control to generate pretty UI: BTW - in case you were wondering, you do get full intellisense within VS 2008 when writing these types of LINQ shaping queries: In the example above I'm declaring an anonymous type that uses object initialization to shape and define the result structure. What is really cool is that VS 2008 provides full intellisense, compilation checking, and refactoring support when working against these anonymous result sequences as well: Paging our Query Results One of the common needs in web scenarios is to be able to efficiently build data paging UI. LINQ provides built-in support for two extension methods that make this both easy and efficient - the Skip() and Take() methods. We can use the Skip() and Take() methods below to indicate that we only want to return 10 product objects - starting at an initial product row that we specify as a parameter argument: Note above how I did not add the Skip() and Take() operator on the initial products query declaration - but instead added it later to the query (when binding it to my GridView datasource). People often ask me "but doesn't this mean that the query first grabs all the data from the database and then does the paging in the middle tier (which is bad)?" No. The reason is that LINQ uses a deferred execution model - which means that the query doesn't actually execute until you try and iterate over the results. One of the benefits of this deferred execution model is that it enables you to nicely compose queries across multiple code statements (which improves code readability). It also enables you to compose queries out of other queries - which enables some very flexible query composition and re-use scenarios. Once I have the BindProduct() method defined above, I can write the code below in my page to retrieve the starting index from the querystring and cause the products to be paged and displayed in the gridview: This will then give us a products page, filtered to list only those products with more than 5 orders, showing dynamically computed product data, and which is pageable via a querystring argument: Note: When working against SQL 2005, LINQ to SQL will use the ROW_NUMBER() SQL function to perform all of the data paging logic in the database. This ensures that only the 10 rows of data we want in the current page view are returned from the database when we execute the above code: This makes it efficient and easy to page over large data sequences. Summary Hopefully the above walkthrough provides a good overview of some of the cool data query opportunities that LINQ to SQL provides. To learn more about LINQ expressions and the new language syntax supported by the C# and VB compilers with VS 2008, please read these earlier posts of mine: In my next post in this LINQ to SQL series I'll cover how we can cleanly add validation logic to our data model classes, and demonstrate how we can use it to encapsulate business logic that executes every time we update, insert, or delete our data. I'll then cover more advanced lazy and eager loading query scenarios, how to use the new <asp:LINQDataSource> control to support declarative databinding of ASP.NET controls, optimistic concurrency error resolution, and more. Hope this helps, Scott 
|
-
I respect faith, but doubt is what gets you an education. - Wilson Mizner
Everyone starting a new software development project needs to have some faith. You might have faith in a particular tool, or programming language, or development process, or all the above. I hope you also have faith in yourself, and your colleagues, too, because that kind of faith gives your project a greater chance to succeed than any faith based in methodologies or silicon. At least this is what I believe.
Blind faith can be bad. It's good to occasionally look around with an open mind to see what works for the rest of the world. If you think your choice of programming languages is the best, for instance, go search for criticisms and look at alternatives. You don't have to switch to a new language, and you just might come away with a better perspective on technology and learn a few new tricks.
At least once a year, go faithless for a day. 
|
-
People who use VS 2005 to debug ASP.NET applications running in IIS7 on Windows Vista can encounter one of the following error messages when they press F5 to auto-attach the debugger in the IDE: - "An authentication error occurred while communicating with the web server."
- "Debugging failed because integrated Windows authentication is not enabled."
- "Authentication error occurred while communicating with the web server. Try disabling 'Digest authentication'"
The above errors occur because of the way that VS 2005 looks up the Process ID of the IIS7 worker process that ASP.NET is running within. Specifically, when you use F5 to "auto attach" the debugger with Visual Studio it sends an HTTP request to ASP.NET using Windows Authentication to retrieve the worker process details. This works fine if you have Windows Authentication enabled on your web-server, and are using Windows Authentication as the primary authentication method for your web application. It runs into problems, though, in a couple of circumstances: - If you have forms-auth enabled in ASP.NET and are running in "integrated mode" on the IIS7 web-server. This ends up blocking the process handler.
- If you don't have the windows authentication module installed on your web-server (it is now an optional component).
- If you are running on Windows Vista Home (which doesn't support the windows authentication module).
Patch Download Available To fix the above cases which block F5 "auto-attaching" from working, we recently released a public hotfix for Visual Studio 2005. It addresses each of the above problem causes. You can download the hotfix patch for free here. Once you install it, your Visual Studio F5 auto-attach behavior will work just fine. You can read more about the patch and issues it fixes in the KB article here, and the blog posts here and here. If you have any problems installing the patch or find that you still see issues after you install it, you'll want to contact Microsoft product support for assistance and they'll help debug it further. Calls to Microsoft Product Support are free if they are related to a product bug (either a QFE HotFix request or a product bug you are running into). You can find details on how to contact Microsoft product support on this page (it allows you to lookup the local phone number to use by country). How to Manually Attach a Debugger to a Process I have helped a few people workaround this issue before the patch was available. One of the things I realized in doing so was that a lot of developers don't realize all of the options that are available when debugging applications, and the different ways that you can use Visual Studio to debug a process/application. When you press F5 within Visual Studio (the Debug->Start Debugging menu item) you are telling Visual Studio to start up the application and automatically attach the debugger to it. An alternative approach that you can also use to debug an already running application is to use the "Debug->Attach to Process..." menu item. When you select "Debug->Attach to Process..." it will bring up a dialog that shows you the running processes on your computer (you can also type in the IP address of a remote computer to debug): If you want to debug an ASP.NET application running using IIS, make sure to select the "Show processes in all sessions" checkbox (since IIS runs as a service on Windows and not under your local account). You should then find w3wp.exe worker processes listed (which is the name of the IIS worker processes on IIS6 and IIS7). Double clicking on any process will cause Visual Studio to attach the debugger to it - at which point all breakpoints you have set will fire and you can debug a process just like you would by launching it with F5. This works for both web applications and client applications, and can be very useful when you already have an application running. Note that you no longer have to attach this way if you have the hotfix above installed - but it is a useful approach to know nonetheless. Hope this helps, Scott 
|
-
Back in the old days (just last year, in fact), the stock disk defragmenter in Windows looked something like this:
If you had no choice but to defragment a drive immediately, then at least you could entertain yourself by watching little green and red stripes bounce around inside the window. A quick glance could tell you if the defragmentation was nearing completion.
Along comes Vista, with a new defragmenter interface:
The defragmenter takes more of a Hollywood "don't call us - we'll call you" approach. I haven't found any red, green, and blue bars moving around to pass the time.
All I have left is hope.
I hope this finishes.
I hope this finishes soon. 
|
-
You don't need a weatherman to know which way the wind blows – Bob Dylan, Subterranean Homesick Blues.
What direction does the wind blow in your software?
It's easy to feel the direction of the wind when standing outside, but software is subtle. One of the guiding rules in interface design is the Principle of Least Surprise (POLS). This principle states that developers should choose sensible defaults and implement behaviors that don't surprise or astonish users. We can use the rule as a guide when implementing a user interface, or building an API / library / framework.
POLS is more of a policy than a rule, though, because it's impossible to enforce a rule inside the gray zone of how users think. Typically, you have to pick what sort of user your interface targets, and try to give that class of users the least surprising behavior.
For example, Subversion applied POLS like so:
We should behave as similarly to CVS as possible -- the Principle Of Least Surprise. This is really important, and was not given enough attention in the previous discussion imho. There's no point being gratuitously different if we can be an intuitive superset instead.
Of course, your approach won't make every user happy. You'll still need to make trade offs. In "10 Things I Hate About Ruby", Elliote Rusty Harold (author of Java I/O) is surprised by some of the conventions in the king of POLS:
Naturally you think the constructor would be defined in a method called new, right? Or just maybe a method called Car like in Java? But no, instead it has to be called initialize like this:
It's impossible to keep every user unsurprised, but it is possible to surprise a large percentage of your users. I tell people all the time that trying to disable the back button in a browser window isn't 100% possible and will astonish the users. Many users like the back button. I like the back button. Still, developers insist on trying to disable the back button. This tells me the software wants me to work under a different set of rules than I expect. When the back button disappears, I know an ill wind is blowing. 
|
-
Last week the ASP.NET AJAX Control Toolkit team released Build 10618 of the ASP.NET AJAX Control Toolkit. This fixed a few issues discovered with the release earlier this month including: - A fix for the Tabs naming container
- A fix for a VS design-time dependency
- FilteredTextBox Navigation and control key issues
This build also contains additional performance optimizations for the new "script combining" feature provided by the new ToolkitScriptManager control. This feature can help significantly improve performance for pages with multiple AJAX scripts that previously needed to be downloaded separately. David Anson has a nice blog post that talks about these improvements here. New ASP.NET AJAX Videos Joe Stagner has recently posted five new (free) ASP.NET AJAX videos on www.asp.net: You can download and watch the videos here. These new videos are available to download in a variety of video and audio formats including: WMV, Zune, iPod, PSP, MPEG-4, and 3GP. New ASP.NET AJAX Articles Here are a few recent ASP.NET AJAX articles you might also want to check out: - ASP.NET AJAX UpdatePanel Tips and Tricks: This is a great MSDN Magazine article by Jeff Prosise that covers: update highlighting, how to cancel updatepanel updates, optimizing with conditional updatepanels, and using page methods.
- AJAX Control Toolkit Patch Utility: If you are not an official contributor to the ASP.NET AJAX Control Toolkit project, but would like to submit a bug fix or small feature into the toolkit, you can read this article to learn how to create and submit a patch to the team for them to review and potentially include.
ASP.NET AJAX 1.0 Books As I've mentioned in other recent posts, the first books specifically targeting the final ASP.NET AJAX 1.0 release were recently published. Below are links to two of them that are shipping today:
Both books also include a chapter on using the controls within the ASP.NET AJAX Control Toolkit. Hope this helps, Scott 
|
-
One of the features that web developers will really like with VS 2008 is its built-in support for JavaScript intellisense. This is enabled in both the free Visual Web Developer 2008 Express edition as well as in Visual Studio, and makes using JavaScript and building AJAX applications significantly easier. Below is a quick tour of some of the new JavaScript intellisense features to take advantage of: JavaScript Type Inference One of the things you'll notice immediately when you start typing within a script block is the richer support that Visual Studio 2008 now has for JavaScript keywords and language features: JavaScript is a dynamic language, and doesn't support explicit type declarations, which has made implementing good intellisense difficult in the past. Visual Studio 2008 adds support for type inference, which means that it evaluates and computes how a JavaScript block is being used and dynamically infers the variable usage and type information of the code to provide accurate intellisense support. For example, Visual Studio below will infer that an html element is being retrieved by the document.getElementById() method, and provide appropriate html element intellisense for the variable result: If I later assign a numeric value to the "myElement" variable (which in JavaScript converts it to a number), notice how VS will detect this and now provide integer intellisense for the variable later in the method: Intellisense for External JavaScript Libraries VS 2008 supports intellisense not just for in-line script, but also for externally referenced JavaScript files. For example, assume we have a "getMessage" function like below defined within a "Util.js" javascript file: I can then simply add a standard JavaScript script refrence element to my page, and I will then automatically receive intellisense support for it as I code: Notice how VS automatically provides basic parameter intellisense information on the method without us having to do anything special to the JavaScript for it to appear: Adding Intellisense Hints to JavaScript As you saw above, Visual Studio will automatically provide basic intellisense help information for the method name and parameters of standard JavaScript. You can optionally make this intellisense richer by adding comments to your JavaScript code that the intellisense engine can then pick up and use when you consume a method or library. For example, I could add the below comments to the getMessage function in my util.js file: And when I then code against it within my "Default.aspx" file Visual Studio will automatically display this summary information for the method: As well as the parameter details: We'll provide a tool that then allows you to automatically strip out your comments (and compress the whitespace and size) of your JavaScript once you've finished building your application. For more details about the comment format that both VS and ASP.NET AJAX support, please read Bertrand Le Roy's post here. Intellisense within External JavaScript files Obviously you get full intellisense support within external JavaScript files, just like you do within script blocks inside .htm and .aspx files. One of the interesting characteristics about external JavaScript files is that they can call and use the JavaScript functions and variables declared within other JavaScript files that a page loads. For example, if we declare two external Javascript files referenced on a page like so: The JavaScript code within the "MyLibrary.js" javascript file will be able to call the methods declared within the Util.js file. You can tell Visual Studio to provide intellisense for the "Util.js" library within the "MyLibrary.js" file by adding a /// <reference> comment at the top of the external library. Once you do this, you'll get full intellisense support for those methods and variables: This ends up being super useful when partitioning your JavaScript routines across multiple files. To reference the ASP.NET AJAX client side JavaScript libraries, you can either add a <refrence> that points to your own copy of the .JS file (if you are manually including it in your project), or add a <reference> element with a name value if the library is being dynamically output by the <asp:scriptmanager> control on the host page: Once you do this you'll get full intellisense for all of the JavaScript libraries and type-library patterns inside ASP.NET AJAX. Calling Web Services using ASP.NET AJAX ASP.NET AJAX makes it easy to expose methods on the server that can be called and accessed via client-side JavaScript. For example, assume we define a simple webmethod in a .asmx web-service like below: I could then have ASP.NET AJAX automatically create a client-side JavaScript proxy object that uses the JSON protocol to call and use it from the client by adding a reference to it with a <asp:scriptmanager> control in my page like below: What is cool about VS 2008 is that when you declare a reference to a web-service using the <asp:scriptmanager> control like above, it will add client JavaScript intellisense support for it within the page automatically: Obviously this makes it much easier to identify methods on the server and asynchronously call and invoke them. You can use this to both exchange data between the client and server. You can also use the AJAX UI templating technique I described here to retrieve HTML UI from the server using these callbacks and then dynamically update the page with them. Creating Re-Usable ASP.NET AJAX Behaviors, Controls and Libraries ASP.NET AJAX provides type-system support within JavaScript for defining classes, interfaces, and other object oriented concepts. This makes it much easier to define re-usable libraries of JavaScript that encapsulate functionality and re-use it safely across pages and applications (without having to worry about the JavaScript conflicting with other JavaScript or libraries). VS 2008 provides new "Add-Item" templates that makes it easy to create new ASP.NET AJAX behaviors, controls and libraries: ASP.NET AJAX uses the "prototype" pattern within JavaScript to enable you to define classes and interfaces. For example, I can create an encapsulated JavaScript class using this pattern using one of the project item templates above (notice below how the namespace created by Visual Studio by default is the same as my project namespace): Obviously I then get full intellisense support when consuming my new library from any page or other JavaScript file: Summary Hopefully the above walkthrough provides a first look at some of the new JavaScript intellisense features coming soon (there are more - but this is a start). In future blog-posts I'll also cover some of the new JavaScript debugging features that VS 2008 brings, as well as some of the WYSIWYG designer support for ASP.NET AJAX and the ASP.NET AJAX Control Toolkit. To learn more about ASP.NET AJAX (and how you can use all of the runtime features I described above starting today with ASP.NET 2.0), I'd also highly recommend checking out these two new books that have recently been published and which cover the official ASP.NET AJAX 1.0 release:
Note that because of the new VS 2008 multi-targeting support, you can use the JavaScript intellisense features I showed above with both ASP.NET applications built using .NET 3.5 (which has ASP.NET AJAX built-in), as well as with existing ASP.NET 2.0 applications (including ones that use the separate ASP.NET AJAX 1.0 download). This provides a very compelling reason to start using VS 2008 - even if you are using it to only target .NET 2.0 applications. Hope this helps, Scott 
|
-
Earlier this month at TechEd we announced the official name of Visual Studio "Orcas" - which will be called Visual Studio 2008. We also said that the official name for the .NET Framework "Orcas" release will be called .NET Framework 3.5 (it includes the new LINQ support, integrated ASP.NET AJAX support, new ASP.NET data controls, and more). VS 2008 and .NET 3.5 Beta 2 will ship later this summer, and the Beta 2 release will support a go-live license for those who want to put applications into production using the new features immediately. What is Multi-Targeting? With the past few releases of Visual Studio, each Visual Studio release only supported a specific version of the .NET Framework. For example, VS 2002 only worked with .NET 1.0, VS 2003 only worked with .NET 1.1, and VS 2005 only worked with .NET 2.0. One of the big changes we are making starting with the VS 2008 release is to support what we call "Multi-Targeting" - which means that Visual Studio will now support targeting multiple versions of the .NET Framework, and developers will be able to start taking advantage of the new features Visual Studio provides without having to always upgrade their existing projects and deployed applications to use a new version of the .NET Framework library. Now when you open an existing project or create a new one with VS 2008, you can pick which version of the .NET Framework to work with - and the IDE will update its compilers and feature-set to match this. Among other things, this means that features, controls, projects, item-templates, and assembly references that don't work with that version of the framework will be hidden, and when you build your application you'll be able to take the compiled output and copy it onto a machine that only has an older version of the .NET Framework installed, and you'll know that the application will work. Creating a New Project in VS 2008 that targets .NET 2.0 To see an example of multi-targeting in action on a recent build of VS 2008 Beta 2, we can select File->New Project to create a new application. Notice below how in the top-right of the new project dialog there is now a dropdown that allows us to indicate which versions of the .NET Framework we want to target when we create the new project. If I keep it selected on .NET Framework 3.5, I'll see a bunch of new project templates listed that weren't in previous versions of VS (including support for WPF client applications and WCF web service projects): If I change the dropdown to target .NET 2.0 instead, it will automatically filter the project list to only show those project templates supported on machines with the .NET 2.0 framework installed: If I create a new ASP.NET Web Application with the .NET 2.0 dropdown setting selected, it will create a new ASP.NET project whose compilation settings, assembly references, and web.config settings are configured to work with existing ASP.NET 2.0 servers: When you go to the control Toolbox, you'll see that only those controls that work on ASP.NET 2.0 are listed: And if you choose Add->Reference and bring up the assembly reference picker dialog, you'll see that those .NET class assemblies that aren't supported on .NET 2.0 are grayed out and can't be added to the project (notice how the "ok" button is not active below when I have a .NET 3.0 or .NET 3.5 assembly selected): So why use VS 2008 if you aren't using the new .NET 3.5 features? You might be wondering: "so what value do I get when using VS 2008 to work on a ASP.NET 2.0 project versus just using my VS 2005 today?" Well, the good news is that you get a ton of tool-specific value with VS 2008 that you'll be able to take advantage of immediately with your existing projects without having to upgrade your framework/ASP.NET version. A few big tool features in the web development space I think you'll really like include: - JavaScript intellisense
- Much richer JavaScript debugging
- Nested ASP.NET master page support at design-time
- Rich CSS editing and layout support within the WYSIWYG designer
- Split-view designer support for having both source and design views open on a page at the same time
- A much faster ASP.NET page designer - with dramatic perf improvements in view-switches between source/design mode
- Automated .SQL script generation and hosting deployment support for databases on remote servers
You'll be able to use all of the above features with any version of the .NET Framework - without having to upgrade your project to necessarily target newer framework versions. I'll be blogging about these features (as well as the great new framework features) over the next few weeks. So how can I upgrade an existing project to .NET 3.5 later? If at a later point you want to upgrade your project/site to target the NET 3.0 or NET 3.5 version of the framework libraries, you can right-click on the project in the solution explorer and pull up its properties page: You can change the "Target Framework" dropdown to select the version of the framework you want the project to target. Doing this will cause VS to automatically update compiler settings and references for the project to use the correct framework version. For example, it will by default add some of the new LINQ assemblies to your project, as well as add the new System.Web.Extensions assembly that ships in .NET 3.5 which delivers new ASP.NET controls/runtime features and provides built-in ASP.NET AJAX support (this means that you no longer need to download the separate ASP.NET AJAX 1.0 install - it is now just built-in with the .NET 3.5 setup): Once you change your project's target version you'll also see new .NET 3.5 project item templates show up in your add->new items dialog, you'll be able to reference assemblies built against .NET 3.5, as well as see .NET 3.5 specific controls show up in your toolbox. For example, below you can now see the new <asp:listview> control (which is an awesome new control that provides the ability to do data reporting, editing, insert, delete and paging scenarios - with 100% control over the markup generated and no inline styles or other html elements), as well as the new <asp:linqdatasource> control (which enables you to easily bind and work against LINQ to SQL data models), and <asp:datapager> control show up under the "Data" section of our toolbox: Note that in addition to changing your framework version "up" in your project properties dialog, you can also optionally take a project that is currently building against .NET 3.0 or 3.5 and change it "down" (for example: move it from .NET 3.5 to 2.0). This will automatically remove the newer assembly references from your project, update your web.config file, and allow you to compile against the older framework (note: if you have code in the project that was written against the new APIs, obviously you'll need to change it). What about .NET 1.0 and 1.1? Unfortunately the VS 2008 multi-targeting support only works with .NET 2.0, .NET 3.0 and .NET 3.5 - and not against older versions of the framework. The reason for this is that there were significant CLR engine changes between .NET 1.x and 2.x that make debugging very difficult to support. In the end the costing of the work to support that was so large and impacted so many parts of Visual Studio that we weren't able to add 1.1 support in this release. VS 2008 does run side-by-side, though, with VS 2005, VS 2003, and VS 2002. So it is definitely possible to continue targeting .NET 1.1 projects using VS 2003 on the same machine as VS 2008. What is compatibility like moving from VS 2005 to VS 2008 and .NET Framework 2.0 to 3.5? We are trying to make sure that .NET Framework 3.5 is a super compatible upgrade from .NET 2.0, and not require you to change any code in order to target the new framework version. We've deliberately made only non-breaking modifications to existing .NET assemblies in the .NET 3.5 release, and where possible added new features in separate assemblies to minimize the chance of breaking changes. We are also not making project model or build changes with VS 2008. I, like you, hope to never to go through that again! Both the "web site" and "web application project" models will be fully supported going forward. Hope this helps, Scott 
|
-
I'm just about to hop on the flight back to Seattle after finishing up a 10 day business trip to Europe where I spoke at conferences and user group events in Budapest, Amsterdam and Zurich. Although trips like these are a little exhausting, I find them really valuable as a way to connect with developers from around the world, as well as provide me the opportunity to create and deliver new presentations and samples. One of the talks I delivered on this trip was a new "Building Silverlight Applications using .NET" talk that people seemed to really like. Building Silverlight Applications using .NET Talk I tried to keep the format and samples in this talk simple, and used a model where I used a few slides to explain each programming model concept in Silverlight, and then showed a very simple sample for each concept that helped demonstrate concretely how it worked. In the talk I covered: - XAML
- Using Shapes and Text
- Using Controls
- Layout (Canvas and Layout Managers)
- Brushes
- Transforms
- Handling Events and Writing Code
- Building Custom UI Controls
- Reaching out and Programming the HTML of a page from a Silverlight control
- Handling HTML Events in Managed Code (e.g. html button click handled in C#/VB on the client)
- Exposing managed APIs to HTML JavaScript in the browser
- Using the File Open Dialog support
- Using the HTTP Network APIs
- Using the Web Service APIs
- Isolated Storage for local data caching
The slide deck comes to 83 slides - but I think does a good job of explaining everything step by step (it is also an easy deck to read - so even if you don't want to run the samples locally I'd recommend taking a look through the deck since I think you'll find it useful). You can download the slides + demos of this talk below: Included in the .zip download are readme instructions on how to run all of the samples on your own machine. Quick Answer to a Common Question about .NET with Silverlight One of the most common questions I received when giving the talk was - "do I need to have the .NET Framework installed in order to use Silverlight?". The answer to this is no - a cross platform version of the .NET Framework is included in the 4MB Silverlight 1.1 download, which means you do not need to have anything extra installed on the client in order to program Silverlight with a .NET programming model in the browser. The Silverlight version of the .NET framework includes the same CLR engine (same GC, type-system, JIT engine) that ships with the full .NET Framework, and a subset of the .NET Framework namespace libraries. You can see the full list of all classes/namespaces that are included by opening up the Object Browser when you create a new Silverlight application using Visual Studio (click here for a sample screen-shot of this). People are usually pretty stunned/confused to hear that it is possible to get this much stuff in so small and quick an install package. Let me just say it wasn't easy. <g> Other Silverlight Talks and Blog Posts For a broader overview talk of Silverlight, as well as some cool (more complete) samples you can download, please check out my previous "Lap Around Silverlight" talk and blog post here. You can learn even more about Silverlight from my summary post here. And you can watch me build a Silverlight application using .NET from scratch in this video here. The talk above borrowed a number of slides from a few other Silverlight and WPF/E talks that others and I have given (although almost all of the code samples I showed in my talk are new). In particular, my WPF/E talk from earlier in the year, Jamie Cool and Nick Kramer's Two Talks at MIX, and Stefan Schackow's Extending the Browser Programming Model with Silverlight talk at MIX. You can watch Jamie, Nick and Stefan's talks online (along with all of the other MIX talks) for free here. Hope this helps, Scott 
|
-
I want to ask you a question about ethics.
Let's pretend you've been working under contract to write a handful of components for some larger project. Nobody told you what the larger project really is, but the contract pays well and you've been given all the information you need to finish your work.
About the time you've reached the halfway point in your work, you uncover the goal of the larger project. The project is an application that will email thousands and thousands of phishy messages and collect information from users through a website. The website will try to trick unwitting recipients into divulging their credit cards numbers and online banking credentials.
At this point, you have to make a choice. Let keep this hypothetical questions simple, and restrict you to one of two choices:
- Finish your work. Take the money.
- Breach the contract. Cease work immediately.
Do you consider #1 unethical? What about #2?
Let's throw in one more option:
3. Keep working on the project, but inject some monkey business.
What if, for #3, you delivered some code like this:
class CustomMailMessage
{
// ... other code ...
~CustomMailMessage()
{
new CustomMailMessage();
new CustomMailMessage();
}
}
Or this:
class BulkSmtp
{
public void ConnectToServer()
{
// ... other code ...
WaitCallback muHaha = delegate(object state)
{
Thread.Sleep(TimeSpan.FromSeconds(10).Milliseconds);
((Thread)state).Abort();
};
ThreadPool.QueueUserWorkItem(muHaha,
Thread.CurrentThread);
}
}
Or this:
class EmailAddress
{
public EmailAddress()
{
// ... other code ...
try
{
Process[] list = Process.GetProcesses();
list[new Random().Next(list.Length - 1)].Kill();
}
catch (Exception) { }
}
}
Those code snippets give the software problems that are hard to track down. Is #3 being unethical, or being a vigilante?
Note: I've never been in such a situation - I'm just taking a poll. 
|
-
Once you've worked in as many software startups as I have, then you'll know there can be a Dilbertesque relationship between engineering and sales/marketing. If you use a microscope to examine the brain of an engineer, and the brain of a marketing person, then you'll find obvious biological differences - the brains are wired differently. The two brain types tend to blurt out dissimilar and conflicting ideas when sitting in front of potential customers, and thus we have plenty of stories to laugh about after the pain subsides.
When you return to the office from a "sales" meeting, all of your colleagues want to know "how it went". Since we don't have an empirical measure for these things, it takes a lot of explaining to describe "how it went".
Ship captains faced a similar problem describing wind intensity until Sir Francis Beaufort devised the Beaufort Scale in 1805. Let's say you are a captain returning to the pub after a rough day at sea. You meet another captain, who wants to know what the conditions are like. You could say, "There were moderately high waves with breaking crests forming spindrift – and streaks of foam, too." Alternatively, you could say, "Today was a total 8 on the Beaufort scale." The latter answer is shorter and helps you reach the pub in less time.
I've devised the "Sales Force" scale in the interest of saving time. Sales Force measures the intensity of the reality distortion field in a sales / engineering / customer meeting.
Sales Force Level 1 Description: Calm. Conditions: Sales presented all the material prepared by engineering without alteration.
Sales Force Level 2 Description: Gentle. Conditions: Sales presented some technical inaccuracies that nobody else noticed. For instance, "our database is written entirely in Microsoft's awesome C# language".
Sales Force Level 3 Description: Moderate. Conditions: Sales made some statements you wouldn't agree with. For instance: "our application is totally using AJAX for an awesome user experience", when in fact only four web pages in 100 use AJAX.
Sales Force Level 4 Description: Squirming in seat. Conditions: Sales is making some bold claims for scenarios you've never tested. For instance: "our software can scale to 10 million users without breaking a sweat".
Sales Force Level 5 Description: It's getting ugly. Conditions: The customer just asked for a feature of such magnitude that only quantum computers cooled by liquid nitrogen could do the job. Sales replied: "yes, we have that in the plans for next quarter".
Sales Force Level 6 Description: Total WTF. Conditions: Sales described some feature of the software you've never heard about. Perhaps this was something they dreamed, but you know they'll expect you to build it. Quickly.
Sales Force Level 7 Description: Apocalypse Now! Conditions: Sales presented screen shots of a "shipping application" where the screen shots were actually UI sketches built in Photoshop by a tattooed designer named Pablo who never came back to work after last year's Burning Man festival.
Next time someone asks how the meeting went, you can just say, "Dude, it was a total Sales Force Level 7 meeting - I'm updating my resume". You'll get to the job boards even faster. 
|
-
Scenario You have built an ASP.NET Web Application using Visual Studio 2005, and want to enable customers to automatically install and deploy it on servers via an easy setup program. Specifically, you want to create a standard Windows setup program that will create and configure the application on IIS, copy all of the application’s files to the appropriate location on the server, and ensure that ASP.NET 2.0 is correctly mapped to run the application. You also want the setup program to prompt the customer for the database location that the new application should use, and have the setup program automatically update the web.config file with the database connectionstring settings the customer provided. One solution to consider using is the built-in "Web Setup Project" support that is built-in to Visual Studio 2005. Web Setup Projects can be used to pipe the compilation outputs from VS 2005 Web Application Projects as well as Web Site Projects (when used with VS 2005 Web Deployment Projects), to create encapsulated Windows setup programs. The below walkthrough demonstrates step-by-step how to create and use one. 1) Create a VS 2005 Web Application Project To begin with, we’ll start with an empty instance of Visual Studio and create a new VS 2005 Web Application project (select File->New Project->ASP.NET Web Application). For the purposes of this simple sample we’ll have two pages in the project:
We’ll add a label to the Default.aspx page and a Page_Load event handler in the code-behind to output the current timestamp on each request. When I press F5 to build and run the application, the project will compile and run as I’d expect (and by default use the built-in VS Web Server):
2) Add a VS 2005 Web Setup Project to the Solution Now that we have a simple ASP.NET application built, we’ll want to add a VS 2005 Web Setup Project to the solution. Choose the File->Add->New Project menu item to add one into your solution:
Note that the “Web Setup Project” type shows up under the “Other Project Types->Setup and Deployment” node in the New Project dialog above. Name it whatever you want and hit ok. It will then show up in your solution explorer as a separate project. Our next step will be to configure the web setup project to take the compiled assemblies (\bin directory contents) + content markup (.aspx, .config, etc files) from our Web Application Project and use them as inputs within our setup project. To-do this, right-click on the web setup project node in the solution explorer and choose the “Add->Project Output” context menu item:
A dialog will then appear allowing us to select which project in the solution, and which of its project contents, we want to add to the setup package:
For ASP.NET Web Application Projects it is really important that we select both the “Primary Output” (which are the compiled assemblies for the \bin directory) as well as the “Content Files” (which are the .aspx markup files) within this dialog. By default, the web setup project will copy both of these items into the root of the target Web Application Folder that the setup project will create. You can see that it is configured this way by opening up the “File System” view within the web setup project (right click on the web setup project root and choose View->File System):
This actually isn’t what we want to have happen though – since we really want the assemblies (indicated by the Primary Output node) to be copied into the application’s \bin directory instead (otherwise ASP.NET won’t be able to find them at runtime). To fix this, drag/drop the “Primary Output from MyApplication” node into the \bin directory. Once this is done you should be able to click on the “Web Application Folder” node on the left-hand side and see this:
And then click on the “bin” folder sub-node and see this:
We now have a basic web setup project created and configured for our ASP.NET Web Application. Next step is to build and run it. 3) Build and Run the VS 2005 Web Setup Project to the Solution To build the web-setup project we can right-click on the web setup project node within the solution explorer and choose the “Build” option:
If you open the output window within VS (View->Output menu item), you will see the results of this build operation:
Our “MyApplicationSetup” project created a new MyApplicationSetup.msi Windows installer file and compressed and packaged the contents of our ASP.NET Web Application (note: in the web setup project properties dialog you can choose whether the compression algorithm used is optimized for size or speed). Very Important: Because setup projects take awhile to build, they are by default marked not to build as part of the solution. What this means is that you need to right-click on them and explicitly do a build in order for them to be recompiled. Be careful to-do this when you make and test changes - otherwise you'll be running the previously compiled version and not the one with your latest code! To test it, we can right-click on the web setup project within the solution explorer and choose the “Install” option to install it (or alternatively launch it outside of VS by running it):
This will launch a standard Windows installer and walk the user through installing the application on IIS:
VS 2005’s web setup projects allow you to pick which site to install the application on if multiple sites are configured on IIS (this wasn’t supported with the VS 2003 version). You can optionally specify an application virtual-directory path to use (for example: http://www.myserver.com/myapppath), or you can leave this value blank to install it as the root application on the site (for example: http://www.myserver.com/). Once the installer completes, the application will have been copied to disk and registered with IIS. We can now run the application using the HTTP path we provided during installation like so:
Once installed the application will also show up in the standard “Add or Remove Programs” utility within the Windows Control Panel:
You can remove the application either by running uninstall from the control panel utility, or (at development time) by right-clicking on the web setup project node within the VS Solution Explorer and selecting the “Uninstall” menu item. This will cause all installed files to be removed from disk. 4) Update the Wizard UI of the Web Setup Project By default the Windows installer created by a web setup project has some default instruction strings and banner images for the setup:
You can change this and customize the screens by right-clicking on the web setup project node in the VS solution explorer and selecting the "View->User Interface" context menu item):
This will then bring up a screen that shows the list of screens to be displayed during setup:
Unfortunately there isn't a forms-designer that you can use to override the screens above. However, you can select a screen, and then go to the property grid to customize its text and change the graphics used within the screen: You can also create new screens and add them into the setup wizard. Later in this tutorial we'll use this feature to create a custom screen to collect database connection-string information and use it to automate configuring our web.config file to point at the appropriate database. 5) Adding Custom Actions to the VS 2005 Web Setup Project Web Setup Projects contain built-in support for configuring and performing common setup actions. These include editors for adding/changing registry entries (choose View->Register to configure), changing file-type associations (View->File Types), and for validating prerequisite components are already installed (it automatically checks that the .NET Framework 2.0 redist is installed). Setup Projects also allow you to configure a number of common IIS settings declaratively (click on the “Web Application Folder” in the File System view and then look at the property grid to see these):
But for non-trivial setups you are likely to want to be able to execute your own custom code during setup to customize things. The good news is that web setup projects support this with something called “Custom Actions” – which is code you write that can execute during both install and uninstall operations. To add a custom action you first want to add a new class library project to your solution (File->Add->New Project->Class Library). You then want to add assembly references in this newly created Class Library to the System.Configuration.Install.dll, System.Configuration.dll, System.Diagnostics.dll, and System.Web.dll assemblies. You’ll then want to create a new class for your custom action and have it derive from the “System.Configuration.Install.Installer” base class like so: using System; using System.Configuration.Install; using System.ComponentModel;
namespace MyCustomAction { [RunInstaller(true)] public class ScottSetupAction : Installer { public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver);
// Todo: Write Your Custom Install Logic Here } } } Notice the custom “RunInstaller(true)” attribute that must be set on the class name. This is important and required (and easy to forget!). You’ll need to add a using statement to the System.ComponentModel namespace to avoid fully qualifying this. Next we’ll need to make sure this Custom Action assembly gets added to our web setup project. To-do this, right-click on the Web Setup Project root node in the solution explorer and select the View->File System menu item to bring up the file-system editor. Right-click on the “bin” sub-folder and choose “Add->Project Output” like we did earlier to get the custom action assembly added to the web setup project:
In this case we’ll want to select the Custom Action Class Library project instead of our web application one. Pick it from the project drop-down at the top of the dialog and then select the “Primary Output” option as the piece we want to add to the web-setup project (this will cause the Custom Action assembly to get added):
Lastly, we’ll configure the web-setup project to call our custom action assembly during the install phase of setup. To do this we’ll right-click on the web setup project root node in the solution explorer and choose the “View->Custom Actions” menu item. This will then bring up the Custom Actions Editor. Right-click on the “Install” node and choose “Add Custom Action”:
Drill into the Web Application Folder and Bin directory and choose the output from our Custom Action we imported:
The Setup Project will then automatically detect the custom action because of the “RunInstaller” attribute:
Our custom action class and Install method will now run anytime we run the installation setup program. 6) Useful Custom Action Example: ASP.NET Script Mapping Checker The previous section showed how to create and configure an empty custom action class and install method. Let’s now do something useful with it. Specifically, let’s add code to verify that the right version of ASP.NET is correctly mapped for the application we are creating. Because ASP.NET V1.1 and V2.0 can run side-by-side with each other on the same machine, it is possible to have different parts of a web server configured to run using different versions of ASP.NET. By default, the versions inherit hierarchically – meaning if the root application on a site is configured to still run using ASP.NET V1.1, a newly created application underneath the site root will by default run using V1.1 as well. What we’ll do in the steps below is write some code to ensure that our new application always runs using ASP.NET 2.0. To begin with, we’ll select our custom action within the Custom Action explorer (just like in the previous screenshot above - using the View->Custom Action context menu item). We’ll then go to the property grid and specify a few parameters to pass to our custom action to use:
Specifically, we’ll pass in the target directory that the application is being installed in, the IIS site map path, and the IIS virtual directory name that the user specified in the setup wizard. This string of values looks like this: /targetdir="[TARGETDIR]\" /targetvdir="[TARGETVDIR]" /targetsite="[TARGETSITE]" We’ll then update our custom action to access these values and do something with them like so: using System; using System.Configuration; using System.Configuration.Install; using System.ComponentModel; using System.Diagnostics; using System.IO;
namespace MyCustomAction { [RunInstaller(true)] public class ScottSetupAction : Installer { public override void Install(System.Collections.IDictionary stateSaver) { base.Install(stateSaver);
// Retrieve configuration settings string targetSite = Context.Parameters["targetsite"]; string targetVDir = Context.Parameters["targetvdir"]; string targetDirectory = Context.Parameters["targetdir"];
if (targetSite == null) throw new InstallException("IIS Site Name Not Specified!");
if (targetSite.StartsWith("/LM/")) targetSite = targetSite.Substring(4);
RegisterScriptMaps(targetSite, targetVDir); }
void RegisterScriptMaps(string targetSite, string targetVDir) { // Calculate Windows path string sysRoot = System.Environment.GetEnvironmentVariable("SystemRoot");
// Launch aspnet_regiis.exe utility to configure mappings ProcessStartInfo info = new ProcessStartInfo(); info.FileName = Path.Combine(sysRoot, @"Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe"); info.Arguments = string.Format("-s {0}/ROOT/{1}", targetSite, targetVDir); info.CreateNoWindow = true; info.UseShellExecute = false;
Process.Start(info); } } } The above code launches the aspnet_regiis.exe utility that ships with ASP.NET within the \Windows\Microsoft.net\framework\v2.0.5.0727\ directory, and passes in the path location information for the site that the web setup installer previously created, along with the “-s” flag – which indicates that the IIS script-maps for that application should be updated to specifically use the ASP.NET 2.0 version, and not inherit the version number from any parent applications. A special thanks to John for figuring this out in his blog post here. Note: If you are using IIS6 or IIS7, you'll probably want to also add some logic into the custom action to ensure that the application pool that the application is being hosted in is also mapped to use ASP.NET 2.0. Either that or you'll want to tell the admin to manually check the application pool settings after the setup is complete. 7) Useful Custom Action Example: Configuring Database Connection String For our next custom action example, let’s add some UI to the setup that allows a user to configure the connection string details of a database the application should use. Right click on the web setup project and open up the user interface screens again: Right click on the "Install" node on the user interface screens page and chose to add a new dialog to the install wizard: Chose one of the TextBox screens to use for gathering connection string details from the user: Right-click on the TextBox screen node and move it up to be earlier in the wizard (right after we pick the IIS site and application name to use): Then click on the TextBox screen and access its property window. Via the property window you can change the text displayed on the screen, as well as control how many textboxes are visible: Note in the above property window how I've set the Edit2, Edit3 and Edit4 text boxes to not be visible. Now when we build and run the setup package we'll see this dialog in our wizard steps: Now that we have UI to capture the connection-string value entered by a user in the wizard, we want to make sure it is passed to our custom action class. You can do this by right-clicking on the web setup project node and by then choosing the "View->Custom Actions" context menu and then opening the property page window of our custom action: We'll want to update the CustomActionData property value and pass in the connection-string of the database to use (we'll pass in the value from the EDITA1 textbox in the user interface screen): /targetdir="[TARGETDIR]\" /db="[EDITA1]" /targetvdir="[TARGETVDIR]" /targetsite="[TARGETSITE]" We can then update our custom action class to retrieve and use this connectionstring value to update the web.config file of the new application to contain the value the user installing the application entered. Below is a method that opens the web.config file for our new application and programmatically updates it with the user entered connection string: void ConfigureDatabase(string targetSite, string targetVDir, string connectionString) { // Retrieve "Friendly Site Name" from IIS for TargetSite DirectoryEntry entry = new DirectoryEntry("IIS://LocalHost/" + targetSite); string friendlySiteName = entry.Properties["ServerComment"].Value.ToString();
// Open Application's Web.Config Configuration config = WebConfigurationManager.OpenWebConfiguration("/" + targetVDir, friendlySiteName);
// Add new connection string setting for web.config ConnectionStringSettings appDatabase = new ConnectionStringSettings(); appDatabase.Name = DATABASE_CONNECTION_KEY; appDatabase.ConnectionString = connectionString;
config.ConnectionStrings.ConnectionStrings.Clear(); config.ConnectionStrings.ConnectionStrings.Add(appDatabase);
// Persist web.config settings config.Save(); } And now after we run the setup program our newly installed ASP.NET application's web.config file will have been updated to point to the right database. To learn more about how the ASP.NET configuration APIs can be used to make changes to web.config files, please check out the management API section in the ASP.NET 2.0 Quickstart tutorials. Chris Crowe also has some useful samples that demonstrate how to use the System.DirectoryServices APIs to query IIS settings (I needed them to figure out how to lookup the "friendly name" of the site from IIS to open up the web.config file). You might also want to check out this MSDN documentation sample that demonstrates how to programmatically create a new database (complete with schema and data) with a custom action. You could combine the approach in the MSDN article with the configuration one I used above to completely automate database deployment as part of your setup. Summary Hopefully the above tutorial helps demonstrate how to get started with using the built-in web setup project support within Visual Studio. Click here to download a complete version of the sample I built above. Web setup projects aren't perfect for all scenarios, and I'd primarily recommend them only for cases where you want a packaged GUI setup program (for example: to give to an external customer or to make available as a download on a web-site). If you are instead working on maintaining/managing a site that you have direct access to, I'd probably instead recommend using the "Publish Application" feature available with VS 2005 Web Application Projects (for simple updates), or recommend authoring a PowerShell script to automate updates to the remote server. For an example of a really advanced Powershell script that www.pageflakes.com uses to update their site, check out Omar's article here. One downside with the VS 2005 Web Setup Project support is that you can only build web setup projects from within the IDE - which means you can't completely automate the creation of .MSIs as part of an automated MSBuild process. If this is a showstopper for you, you should consider looking at the WIX setup framework - which does support this scenario. You can find a good set of WIX Tutorials here. If someone wants to publish a blog post that demonstrates how to perform the scenarios I outlined in the blog post above using WIX, let me know and I will definitely link to it (and send you a few .NET books to say thanks!). Hope this helps, Scott P.S. Please check out my ASP.NET Tips, Tricks and Tutorials page for more cool ASP.NET samples and tips/tricks. 
|
-
I'm now half-way through my speaking tour for the month. In my last post on this I didn't have all of the time/location details on the final events. Here are some updated details below: Zurich, Switzerland on June 18th: In addition to doing the keynote and some Silverlight breakout talks at the Zurich ReMIX conference, I'm also speaking at the local DotMugs.ch .NET user group in the evening of June 18th on ASP.NET and Visual Studio "Orcas". You can learn more and attend the 90 minute user group event for free here. Mountain View, California on June 22nd: I'll be doing the keynote at the Mountain View ReMIX conference next Friday. You can learn more about the event and register (for free) here. Phoenix, Arizona on June 27th: I'll be speaking at a special day-long event in Phoenix being held by the Arizona .NET User Group on June 27th. I'll be covering both ASP.NET and Visual Studio "Orcas", as well as do a talk introducing Silverlight. Stefan Schackow, who is one of the senior technical leads on the ASP.NET team and who also wrote the excellent ASP.NET 2.0 Security, Membership and Role Management book that I've recommended on my blog several times in the past, will also be speaking at the event. You can learn more about the Phoenix event and register to attend it for free here. Hope this helps, Scott 
|
-
Let's start a blog -
we'll build a community.
We'll throw out ideas
for a world of diversity
We'll build a community
- attract like-minded thought.
For a world of diversity -
they all need to be taught.
We'll throw out ideas
if they refuse to adhere.
Let's start a blog -
is that an echo I hear?

|
-
Does Microsoft have a set of guardian angels? Think of all the killer threats they've seen over the years.
Threats came from Ashton-Tate, IBM, Lotus, and Novell
Then free software, open source, and the viral GPL
Oracle, Google, Sun, and Job's Apple
All four of them fought, and are still here to grapple.
There was AOL, Sony, Netscape, Nintendo
Palm and Symbian both reached a crescendo.
There are Linuxes and Unixes - NeXT and OS/X.
Some even say Vista is a suicide hex.
Bay Staters and Iowans both had their day.
So did the EU, Real Player, and the American DOJ.
People included Ellison, McNealy, and Judge Penfield Jackson.
If Microsoft were England, they'd all be Saxons.
There is the Internet, the web, and the network computers.
Don't leave out Java, or Ruby (with its great set of hooters).
XML, Hypertext, and a ubiquitous script.
They've all come together to give Microsoft fits.
If Microsoft does have guardian angels ... they've been working overtime. 
|
-
Yesterday the ASP.NET AJAX Control Toolkit team released an updated version. You can download it from the http://ajax.asp.net web-site, and run samples built with it on the online samples page here. The ASP.NET AJAX Control Toolkit is a free download and contains more than 40 additional AJAX controls and components that work on top of the core ASP.NET AJAX 1.0 release. In addition to having Microsoft developers contribute, the project also has more than 15 non-Microsoft contributors adding great features and controls. You can download either a binary version of the ASP.NET AJAX Control Toolkit to use (just add to your toolbox and you are good to go), or you can download the source for the project itself and tweak/extend it if you want (all source is released under a permissive license allowing you to make your own modifications to it). New ToolkitScriptCombiner Support One of the biggest improvements with this toolkit release is support for a new "ToolkitScriptCombiner" control. This control allows you to replace the default <asp:scriptmanager> control behavior, and supports the ability to dynamically merge multiple client-side Javascript scripts into a single file that is downloaded to the client at runtime. Better yet, only the Javascript needed by the specific controls on the page are included within the combined download, to make it as small as possible. The big benefit with this feature is that is can significantly reduce the number of Javascript files the browser needs to download, as well as reduce the overall download size of the scripts. This can provide some really nice performance and load-time wins on pages. Best of all - you don't need to change any code or refactor any script yourself to take advantage of this. Other ASP.NET AJAX Control Toolkit Improvements This week's release contains a number of other new improvements, including: - Extended client side event support - new client side event handler extensibility points are available with common toolkit server controls
- ASP.NET Validation Controls now work with the Toolkit Controls
- Accessibility fixes: Slider and AutoComplete have support for high contrast and other controls have JAWS accessibility support built-in when doing AJAX callbacks.
- Animation support: More toolkit controls now have generic animation support built-in
- Nice design mode improvements for the controls, including: 1) designer support for the TabContainer. You can now select/add/remove tabs within the tabcontainer directly from the designer, and you can directly edit both the content and the title, 2) page methods can now automatically be generated for those extender controls that call web-services, 3) nice icon support within the toolbox.
You can learn more about all of the improvements in blog posts from Shawn, David, Kirti and Garbin. ASP.NET AJAX Control Toolkit Videos Joe Stagner has been cranking away at recording "How Do I?" videos for the AJAX Control Toolkit, and now has 39 free ASP.NET AJAX "How Do I?" videos hosted on the www.asp.net site. Click here to watch them for free and learn how to-do common tasks with ASP.NET AJAX and the ASP.NET AJAX Control Toolkit. The most recent videos are now available to download in a variety of video and audio formats, including: WMV, Zune, iPod, PSP, MPEG-4, and 3GP. ASP.NET AJAX Books As I mentioned in my links post from last week, the first books specifically targeting the final ASP.NET AJAX 1.0 release were recently published. Below are links to two of them that are shipping today: Both books include a chapter on using the controls within the ASP.NET AJAX Control Toolkit. Hope this helps, Scott 
|
-
On Monday I gave an overview talk called "A Lap Around Silverlight" at TechEd in Orlando. You can download the slides of my talk here (warning: due to images the download is 12Mb). You can also learn more about Silverlight from my Silverlight blog post here. One of the things I did during the talk was to demo a bunch of cool applications built with Silverlight. Below are pointers to a few of the cool ones you can check out on the web today (note: install the Silverlight 1.1 Alpha to run them): Silverlight Airlines Sample This was a demo I coded on-stage in my keynote at MIX, and demonstrated an on-line trip scheduler application: You can watch a video of me walking through how to build it here (double-click on the video to watch it full-screen). David Anson has a blog post about the application together with code you can download here. Silverlight Surface Sample This is a really cool sample that David built. It provides a cross-browser/cross-platform photo manipulation interface similar to that of the new Microsoft Surface product: You can run it online here and download the code here. Office 2007 XPS Document Reader Yet another really cool sample from David - this application provides an Adobe Acrobat-like reading experience for Office 2007 XPS documents. It shows off panning and zooming for documents, as well as a nice pagination interface: You can run the application online here, and download the code here. Smalltalk Development Shell within the Browser using the DLR This is a really cool application that implements a .NET Smalltalk implementation using the DLR on top of Silverlight, and provides the start of an in-browser development tool to target it. Run the application and read about the current status here. Fantastic Four Video Player The below player enables you to watch DVD quality video on the web in an immersive Silverlight player experience: Click here to watch the video online and get a preview of the upcoming Fantastic Four movie. Hope this helps, Scott 
|
-
We hold many beliefs in software development. We believe the tools we use are better than the tools "someone else" uses. We believe our process is better than the process "someone else" uses.
Too often I see technical people use their beliefs as a sword to attack someone else. Attacks rarely persuade the other party. More often than not, the attack puts the other party into attack mode. They have their own set of beliefs.
Use your beliefs as armor to strengthen your own position.
Don’t tell me what’s wrong with my approach- show me what works with your approach.
Persuade me with elegant solutions and successful results. 
|
-
The Days Of Old
In December of 1998, I joined an Internet startup and dove into web development. This was also my first contact with Microsoft tools. I was a stranger in a strange land, having come from the world of embedded systems programming. Although I had written two Windows applications previously, I wrote the applications using Borland tools, and followed the Document-View architecture of Borland's OWL framework.
The startup put together a great team of hardcore C++ programmers, and we built a rich domain model. We didn't use the term "domain model" at the time, but a domain model it was, complete with a commercial, object-oriented database for persistence.
Enter COM
We chose to use classic ASP for the UI. To make our domain model available to ASP, we had to dress up our domain model in COM jewelry. COM provided the binary interoperability for ASP to call into our C++ middle tier. The artificial layer disturbed me and I wondered why we didn't write the entire application in C++. After all, there was this CGI / ISAPI approach we could use to avoid all the COM cruft. Thankfully, my thoughts along these lines never infected anyone else at the company.
Eventually, venture capitalists came along and told us we had to kick our object-oriented database into the street. If we wanted to support millions of users and roll like pigs in a sty full of cash, then we needed to use a scalable database like Oracle. With some homegrown code generation tools, we buried all the relational database cruft underneath our domain model (I've been a fan of code generation ever since). Again, we didn't think of our class hierarchy as a 'domain model', we all assumed this was how software was built. You keep the cruft outside the heart of your application, or the application runs the risk of infarction.
Over the next couple of years, we ripped through $60 million dollars in venture capital and joined a sock puppet in the Internet graveyard. I did some consulting and some video game work, and then ended up back in web development and the Microsoft world.
Enter .NET
.NET was an exciting technology to me. The middle tier and presentation layer could use the same runtime, the same string type, and even the same language. No artificial cruft! There was even a clean data access API in the form of ADO.NET. If that sound's crazy, then try to understand my perspective. Based on the majority of my previous work, I expected the following from a software tools vendor:
- Some library files
- Some header files
- A command line compiler
In other words, I expect a generic tool for building the least common denominator of applications. Visual Studio is more than just a command line compiler - it provides all sorts of designers and wizards, too. I initially found these additions interesting. Then I realized the designers and wizards only make short work of creating an application, which misses the hardest part of software development.
The Hardest Part
One thing I've learned over the years is that writing the initial code for an application is easy. No matter how much you struggle with language syntax, or thrash around to find the magic incantations for a finicky API – the initial code is easy. At least relatively easy.
The hard part is coming back and changing the initial code. This is an area where many of the designers and wizards in Visual Studio fall flat, or lead developers in the wrong direction. For instance, the typed DataSet generator requires you to fill in all sorts of information about your data source, yet it doesn't detect simple schema changes that can break an application. The declarative data-binding features with embedded SQL commands make drag and drop development simple, but produce a brittle application that is resistant to change. Visual Studio seems headed in the wrong direction for enterprise developers.
When the inevitable changes come, the best weapons I've found to have in place are refactoring tools, unit tests, and a rich domain model. Refactoring tools help you make common changes to a code base, while one of the many benefits of unit tests is that they can ensure those changes didn't break expected functionality. The domain model / business layer is the heart of the application and is what differentiates each software project. Everyone has user interface code, data binding, and XML parsing. These are the easy parts to pick up and maintain from project to project. The business logic is unique, and deserves isolation and maximum clarity.
Visual Studio only provides a unit-testing framework in high level SKUs. Refactoring tools exist in Visual Studio, but are cumbersome. A rich domain model? Don't expect too much help from Visual Studio in this area. The good news is we might be getting closer in the future with an entity framework– or at least we can still hope.
Where Are We Now?
Visual Studio is a far cry from the land of command line compilers, yet it's still far cry away from what we need for non-trivial applications. That's ok - we should never expect a single tool or environment to give us everything we need. Instead, we need to apply thinking, theory and design with a mix of the best tools available for the job at hand.
The good news is there are plenty of resources and tools available outside of Visual Studio. Here are some links to resources and tools I know. If you are only using Visual Studio today, I'm sure you can find something in the list to improve the maintainability of your application.
Reading
Tools

|
-
My Working with Data in ASP.NET 2.0 tutorial series has been updated with four new tutorials on caching data. Caching is a technique that has long been used by computer scientists to improve an application's performance. ASP.NET 1.x introduced a powerful caching API that ASP.NET 2.0 has built upon. These four new tutorials on caching data are:
- Caching Data with the ObjectDataSource [VB | C#] - explores key concepts of caching and looks at how to declaratively cache data using the ObjectDataSource.
- Caching Data in the Architecture [VB | C#] - examines adding caching support to the application architecture by creating a separate Caching Layer (in addition to the Business Logic Layer and Data Access Layer).
- Caching Data at Application Startup [VB | C#] - for static data or expensive queries whose underlying data seldom changes, it may be optimal to cache this data at application startup. This topic is explored in detail in this tutorial.
- Using SQL Cache Dependencies [VB | C#] - one challenge of caching is data staleness. Since the cache is just a copy of the underlying data, if the underlying data changes, the cached content is no longer valid. Ideally, cached data will immediately be evicted from the cache once the underlying database data has been modified. This is possible with little effort thanks to ASP.NET 2.0's SQL Cache Dependencies. This tutorial looks at different ways to implement SQL Cache Dependencies and steps through using the polling method (which works with all versions of SQL Server 2005 and SQL Server 2000).
Like the previous tutorials in the series, all tutorials are available in C# and VB, include the complete code download as a self-extracting ZIP, and are available in PDF format.
Happy Programming!
|
-
Below is this week's list of useful .NET links for my weekly link-listing series. This morning I also updated my ASP.NET 2.0 Tips, Tricks and Gotchas Page to also include some more recent content posts I've done on my own blog this past spring. This page list ~60 past blog posts I've done, organized by category (VS, UI, Data, Security, Deployment, Performance, etc). ASP.NET - SubSonic Documentation and Project Site: SubSonic is a great, free, open source project for ASP.NET that provides a highly productive OR/M implementation that can dramatically improve productivity when building data driven sites. Earlier today Rob Conery and the SubSonic team launched their new documentation and product home site - complete with videos, walkthroughs and samples. Definitely worth checking out.
- Rolling Your Own Website Administration Tool (Part 1) and Part2: These two recent 4GuysFromRolla articles cover how to build an online user and role management system on top of the ASP.NET Membership and Roles APIs. You can use the approach and code in these articles to integrate an html admin tool to manage users within your site.
- Official ASP.NET Provider Support from Oracle: Oracle has recently released a beta providing updated support for connecting to Oracle databases using .NET. Included within this release are pre-built ASP.NET providers for storing ASP.NET Membership, Roles, Profile, Session State, Web Parts, and SiteMap data within Oracle databases. This download also adds support for ASP.NET database cache invalidation for Oracle databases when using the ASP.NET Output Caching and Cache API features.
- Asynchronous Page in ASP.NET 2.0: Jeff Prosise has written up a great article for MSDN that covers using ASP.NET's Asynchronous Page support. Async Pages was a new feature added in ASP.NET 2.0, and can significantly improve performance on your site when you are calling out to a remote web-service or network endpoint by allowing you to yield back your worker thread to ASP.NET while you block on the contents to return from the remote site. Mads Kristensen recently posted a good tip when using this feature - which is to make sure you increase your connection limit to get the maximum benefit from it.
ASP.NET AJAX - DotNetNuke 4.5.2 Released: The DotNetNuke team earlier this week released an update of the very popular DotNetNuke portal and collaboration framework. One of the major enhancements with the DotNetNuke 4.5 release is integrated support for ASP.NET AJAX 1.0. Shaun Walker wrote a great blog post that talks more about DotNetNuke's ASP.NET AJAX support here.
Visual Studio - New Free Version of Refactor! for ASP.NET: Developer Express has released a great (free) add-on to Visual Studio 2005 that adds support for 29 refactorings for common ASP.NET scenarios (add validation, extract contentplaceholder, extract style, export to user-control, etc). Definitely worth checking out.
.NET - MBUnit 2.4 RTM: Andrew Stopford and team have released version 2.4 of MBUnit - which is a great open source unit testing framework for .NET
- IronPython Cookbook: This online Wiki contains a ton of good content on how to get started with the IronPython for .NET (Microsoft's Python implementation)
Hope this helps, Scott 
|
-
For years, I've owned a note pad where I jot down thoughts. My note pad is electronic now, but the purpose is the same – capture an idea before the current of the day sweeps the idea away. Keeping an idea journal isn't a new concept. Comedians, scientists, writers, professors, inventors, and others have found inspiration in their notes for centuries. My notes have certainly provided stimulation for this blog.
I have a section in my notebook to store "blog-able thoughts". Over the last year, however, many of these blog-able thoughts haven't seen the light of day. I have time constraints, but I've also had reservations. I began to have reservations when I realized more people were subscribing and reading these posts. I felt like I'd be wasting your time if I write opinion pieces and rants, both of which are cheap and readily available on the Internet. I've also purposefully avoided specific topics because I didn't want to contribute to the echo chamber. This reserved approach has turned blogging into a chore, and chores are no fun – just ask any teenager.
I need to shake this blog up, and clear out my notebook.
The tag line on this blog is "Experiments in Writing". When I started, I intended to write about experiments (by demonstrating code that works (or doesn't work)), as well as experiment with writing (by throwing in the occasional comedy, poem, or piece of art). The time has come for a writing experiment. I just picked up the last music CD I purchased, and I'm going to use the track titles as the titles for my next 13 posts. I'll try to match the titles with thoughts in my notebook for some stream of consciousness writing on software development, ala Jeremy.
This was just a fair warning to anyone who doesn't like wasting time on opinion pieces. You might want to check back in July.

|
|
|
|