Vitaly's WebLog
Software development, startups, marketing

.NET Framework Programming Model for Add-Ins

March 24, 2008

It seems that there is still lot to learn about .NET Framework 3.5. I've found today (thanks to Daniel Moth) that is one more interesting feature was added in .NET Framework - Programming Model for Add-Ins. Basically, it allows you to build application that can be extended by add-ins. You may say that it is not a great task to build your own model. Yes, it is easy to. To build simple model. But what this new programming model offers is a complete solution. There are the following services that you can leverage:

  • Independent Versioning. You may want your host app and add-ins to version independently.
  • Discovery and Activation services
  • Isolation Levels. You may want load your add-ins in separate application domain. Separate from a host app or in seperate app domain for each add-in. There are several levels of isolation you can choose from. 
  • Lifetime management. Because of the facility above (isolation Levels) you may be not able to rely on Garbage Collection. Fortunately, there are facilities to manage lifetime of objects in this programming model.

I would definitely recommend reading a bit about this on MSDN if you are building Smart Clients sometimes. There are also some good resources on Daniel's blog that will help you to start. By the way, Daniel calls this as Managed Add-ins Framework (Great name, except of usage of 'Framework' term, that is a bit overused already) Interesting, if that is official name of this feature (I did not find mentions of MAF in official docs)?

 


Missing Immediate Window in VS2008

January 28, 2008

Immediate window is useful when debugging your application. If you used to it in previous versions of Visual Studio you may be surprised that it absents on its usual place in VS2008. Fortunately, you can add it back. Right click on the toolbar area, select Customize, find your beloved Immediate menu item and drop to the main menu (or to toolbar if you like).

Adding Immediate Window Back in VS2008


How to make incremental DB update script in VS2008

January 20, 2008

One of the most tedious tasks in database-driven software development is to make database change scripts. You meet it just as you product version becomes higher than 1. You usually have to maintain create script that creates you DB from scratch and also change script(s) that will upgrade existing databases of previous version(s) to the latest one. And those databases most probably have customer data in them that you cannot damage.

In the latest release of Visual Studio there is new type of database projects that helps maintaining your database scripts significantly. I've already wrote review of new features, but such important topic as generation of change scripts in missing in that post, so I decided to write new post on it.

From the first sight it seems that VS can generate only create scripts, which it places in /sql folder by default. Hopefully, it also can generate change script, although this feature not so easy to discover. It can be found in database compare tool. It generates scripts based on differences between two databases (between schema that you have in DB project and some DB instance). It is not well automated, so you have to copy the script it generates, review it manually, and save in a file yourself.

Some manual changes may be need in script. One good example: if you have used rename wizard to rename column in some table you may expect that data that was in that column will be kept by a script. Unfortunately, this type of change is not handled well by VS 2008. Yes, there is warning in UI, but who reads those warnings :-)

 VSDBP_RenameWarning

There is option in project properties "Perform 'smart' column name matching when you add or rename a column". Here is what MSDN says about this option:

Specifies whether to apply a heuristic when you deploy updates to determine when to rename a column instead of performing a DROP and an ADD operation. The heuristic is based on the properties of the column and the names of the source and target columns.

I hoped that setting this option will fix the problem with column rename, but unfortunately this did not work for me. I tried renaming CategoryName -> NewCategoryName and CategoryName -> Category1. In both cases this did not work. Perhaps they need to provide more info on the heuristic they use...

There is also protection from data loss. You can control it by setting in project properties. Unfortunately, changing this setting did not work for me too.

VSDBP_SchemaUpdate

VSDBP_Properties

Anyway, this is undoubtedly a great feature. And should help maintaining incremental update scripts a lot.


.NET Framework Library Source Code now available

January 17, 2008

Scott Guthrie announced that source code of .NET Framework library is now available. You can drill down to code written by Microsoft when debugging your application in Visual Studio 2008. And you even see developers comments in source code :-)

Today I'm happy to announce that this is now available for everyone to use. Specifically, you can now browse and debug the source code for the following .NET Framework libraries:

  • .NET Base Class Libraries (including System, System.CodeDom, System.Collections, System.ComponentModel, System.Diagnostics, System.Drawing, System.Globalization, System.IO, System.Net, System.Reflection, System.Runtime, System.Security, System.Text, System.Threading, etc).
  • ASP.NET (System.Web, System.Web.Extensions)
  • Windows Forms (System.Windows.Forms)
  • Windows Presentation Foundation (System.Windows)
  • ADO.NET and XML (System.Data and System.Xml)


Here is sample code snippet. This is the beginning of HttpRuntime.ShutdownAppDomain method:


Handling Database easily with Visual Studio 2008

January 12, 2008

Overview

Visual Studio 2008 Team System has new type of database projects that are much different from those we had in Visual Studio 2005. There is a number of extremely useful features that should make you development much easier. Most of this functionality was previously introduced in Visual Studio 2005 Database Edition. It was released much later than Visual Studio 2005 itself, so some developers (including me) accidentally missed its announcement. Now these tools are integrated into Visual Studio 2008 and replace old database projects.

You start from creating new schema or importing schema of existing database into VS database project, which is presented by separate scripts for each database object. Visual Studio creates quite good catalogue structure by default, but if you have large database then you may add your own folders to better organize your project. As there is separate script file for each database object, it becomes much easier to track changes when your Database Project is put under source control.

After you have imported schema of existing DB (or created new one from scratch), you can easily deploy your DB to any instance of SQL Server and work with it while offline using your private SQL server instance. Visual Studio merges all small separate scripts into several large ones, so you can also use those scripts to manually create database.

To navigate among you database objects, besides Solution Explorer, you can use Schema View pane, that displays database objects as SQL Server Management Studio or Server Explorer does. You also can filter objects if you have large database.

Perhaps the most awesome feature of new database project is design-time validation of your scripts. Visual Studio uses your local database to validate scripts as you type them. It is claimed that you must have either Developer or Enterprise edition of SQL Server locally installed, but it seems that most of the features work ok with SQL Express.

To ease the rename of database objects, Visual Studio provides refactoring wizard. It makes it really painless to rename database tables, columns, views and other objects, because it finds all places where old name was used and provides preview screen with changes for you. There are no other refactoring methods than rename now, so it is not quite clear why the only item "Rename" has been put in "Refactoring" menu. Perhaps there will be some more however...

Another new powerful feature is database unit tests. Visual Studio automates creation of unit tests for database object just as it done for C# and VB code. Good compliment for unit tests is new feature that allows you to load test data in your database. It loads randomly generated values in tables you specify. You can set-up it to load data before executing unit tests. It also can be used for performance testing to foresee how your DB will function on large volumes of data.

And finally, there is handy tool for comparing schemas and data between databases. It is buried in UI, however, and not so easy to find. See screenshots below for help.

Creating Database Project

VS2008DBP_Create Here is where you start from.

You can select to create database project using wizard. There is nothing special that can be made only in the wizard, but it allows setup your project quicker, especially if you are not too familiar with this new type of projects yet. Wizard asks you for options of your database and allows you to import schema of existing database.

VS2008DBP_Wizard_Properties VS2008DBP_Wizard_DbOptions VS2008DBP_Wizard_ImportSchema VS2008DBP_Wizard_BuildAndDeploy

Project Structure

Here is what we have after wizard finishes. Each database object creation script is placed in a separate file.

VS2008DBP_ProjectFiles_Overview      VS2008DBP_ProjectFiles_Tables

 

Design-time validation

I've intentionally made mistake in a column name. Visual Studio immediately shows error message in Error List pane. Unfortunately, error is not highlighted in code editor, but when you click on error message you get positioned on the correct place in code (this works not always, however).

I love this feature!

Another good use of validation is to check existing database for mistakes. You can import it's schema into new database project and build it to start validation.

VS2008DBP_DesignTimeValidation

Schema View Pane

You can make some changes to schema here and easily navigate through you database.

VS2008DBP_SchemaView

Refactoring

Yet one very powerful feature. If you had to rename a column in a large DB you would appreciate this new rename helper.

VS2008DBP_Refactor

VS2008DBP_Refactor_Preview 

Comparing databases

No need to use 3rd party utilities anymore. You can compare databases or database projects in Visual Studio now. Note the toolbar button that the red arrow pointing at - it starts compare wizard.

VS2008DBP_CompareSchema

Here is how results of comparison look like.

VS2008DBP_CompareSchema_compared

Loading Database with test data

Loading database with test data is very useful for unit tests and also can be used for performance testing. To load you DB with test data you add new item, Data Generation Plan, to you project.

VS2008DBP_DGP

Then you specify what tables to fill with data, how many records to add and start data load by clicking on toolbar button.

VS2008DBP_DGP_SettingsAndPreview

Unit Tests

To create Unit Tests for your stored procedure you select it in Schema View and select Create Unit Tests in context menu.

VS2008DBP_UT

Wizard asking you for a list of procedures to generate unit tests for and details abut project that will host your unit tests.

VS2008DBP_UT_Create

If you selected to create new project, Visual Studio asks you for it's properties. Note that you can automatically deploy database to your database server and load it with a test data as it is configured in your Data Generation Plan.

VS2008DBP_UT_ProjectConfiguration

And here is how result looks like. You can go on and customize your Unit Tests as you need.

VS2008DBP_UT_Generated 

Conclusion

Undoubtedly, new database projects are a great feature. What is cool is that you can set-up really solid solution for your development environment with Visual Studio 2008 and Team Foundation Server. And new features of database projects add missing parts to that. You now can test code in your database objects by running unit tests in nightly builds. And you can validate that only valid code comes to Source Controls using Continuous Integration. That all was possible with C# and VB code previously, but now you need not worry for your stored procedures too.

Even if you do not want to use database project as part of a solution, you may want to use some of its useful features on your stand-alone database:

  • You can validate stored procedures, functions and other objects in your database.
  • You may want to load you database with test data for performance testing.
  • You also can use compare wizard to see changes between your databases.
  • And, finally, you can use renaming wizard to easily rename you database objects if you need to.

Here you will find official documentation (that is quite good).


TFS 2008 Power Tools Released

December 22, 2007

Microsoft released Team Foundation Server 2008 Power Tools. This is update of power tool pack that was previously released for TFS 2005. Now it is compatible with VS 2008, includes some new tools that were absent in 2005 version and it does not contain some tools that were already moved to VS 2008. Although this package is primarily aimed to Visual Studio 2008 and Team Foundation Server 2008, most of the tools work ok with VS2008 + TFS2005 bundle and some of them even work with VS2005+TFS2005 bundle (you can use command line tools, that are not integrated into VS IDE).

If your team is using Team Foundation Server, then this it a must-have addendum to Team Explorer. Here is download link. Below is my humble review of the features that I think worth mentioning.

Work Item Templates

When you are creating more than one work item, some fields are often the same. Instead of tediously entering field values for each WI you can create WI templates and automate you work.

There are two ways to use this feature:

- When creating work item you can choose template to base it on.

- You can apply template to existing work items. Batch changes also can be made in Excel, but with WI Templates you now even do not need to leave VS.

I find this feature extremely useful. It really boosts your productivity when working with TFS.

VS2008_TFPT_WITemplates

Find in Source Control tool (new)

Now it is possible to search for files that are checked out by particular user. There is also wildcard search and enhanced search for changeset. Previously we had to use TFS sidekicks for that…

VS2008_TFPT_FindInSC_Menu

VS2008_TFPT_FindInSC_Changesets

Build Notifications (TFS 2008 only)

You can subscribe to receive queued, started, or completed events notification across several instances of TFS. Application resides in Windows Tray area. It is started outside of VS IDE, that is confusing...

VS2008_TFPT_BuildNotification_Menu

Unfortunately, this feature runs only with TFS2008. So if you are using VS2008 and TFS2005 bundle you must use old methods. I wonder why MS announcements and release notes miss such important info sometimes

TFPT.exe

This is command line tool that was in the previous version of Power Tools. It has some new commands however. The best description would be to print its help:

TFPT_help

Process Template Editor

Just in case you find graphical user interface to be more convenient than editing XML files, this tool is for you. Very helpful tool for those who are in charge of defining work items for a team!

VS2008_TFPT_ProcessEditor_Menu

VS2008_TFPT_ProcessEditor_Layout

 

Conclusion

TFS 2008 Power Tools pack contains not only tools for power users, but also several very useful utilities, like WI Templates and Find in Source Control tools , that are a must to have for every TFS user.

Microsoft are closing the gap of missing functionality, but this happens too slowly. It took 3 years for them to add such important feature as status search that is present in VSS. While they position TFS as a higher-level product than VSS, then it must cover functionality of its smaller brother. This is magnified by the fact that most TFS users are VSS users in past, so it is confusing for them not to find functionality they used to.

And there are still some features that are obviously missing in TFS. To count just a few:

- More easy way to rollback changeset

- More easy way to unlock files checked out by someone else

- More easy way to delete WI

I know that all of these are available from command line, but they are inconvenient to use. If you ever tried to unlock someone’s changes you know what I mean…

Anyway, TFS is becoming more mature with each release of this kind and that is great that they listen what users want. That is great product undoubtedly!