BusinessRx Community

Dedicated to the advancement of software, technology and the people who devote their lives to it.

Welcome to BusinessRx Community Sign in | Join | Help
in Search

BusinessRx Reading List

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.

Browse by Tags

All Tags » Community News » Visual Studio   (RSS)

  • Visual Studio 2010 Keyboard Shortcuts

    Earlier this week the Visual Studio team released updated VS 2010 Keyboard Shortcut Posters.  These posters are print-ready documents (that now support standard paper sizes), and provide nice “cheat sheet” tables that can help you quickly lookup (and eventually memorize) common keystroke commands within Visual Studio.

    image

    This week’s updated posters incorporate a number of improvements:

    • Letter-sized (8.5”x11”) print ready versions are now available
    • A4-sized (210x297mm) print ready versions are now available
    • The goofy people pictures on them are gone (thank goodness)

    The posters are in PDF format – enabling you to easily download and print them using whichever paper size is in your printer.

    Download the Posters

    You can download the VS 2010 Keybinding posters in PDF format here.

    Posters are available for each language.  Simply look for the download that corresponds to your language preference (note: CSharp = C#, VB = VB, FSharp = F#, CPP = C++). 

    Hope this helps,

    Scott

  • Introducing ASP.NET MVC 3 (Preview 1)

    This morning we posted the “Preview 1” release of ASP.NET MVC 3.  You can download it here.

    We’ve used an iterative development approach from the very beginning of the ASP.NET MVC project, and deliver regular preview drops throughout the development cycle.  Our goal with early preview releases like the one today is to get feedback – both on what you like/dislike, and what you find missing/incomplete.  This feedback is super valuable – and ultimately makes the final product much, much better.

    ASP.NET MVC 3

    As you probably already surmised, ASP.NET MVC 3 is the next major release of ASP.NET MVC. 

    ASP.NET MVC 3 is compatible with ASP.NET MVC 2 – which means it will be easy to update projects you are writing with MVC 2 to MVC 3 when it finally releases.  The new features in MVC 3 build on top of the foundational work we’ve already done with the MVC 1 and MVC 2 releases – which means that the skills, knowledge, libraries, and books you’ve acquired are all directly applicable with the MVC 3 release.  MVC 3 adds new features and capabilities – it doesn’t obsolete existing ones.

    ASP.NET MVC 3 can be installed side-by-side with ASP.NET MVC 2, and you can install today’s “Preview 1” release on your machine without it impacting existing MVC 2 projects you are working on (they will continue to use MVC 2 unless you explicitly modify the projects to retarget them to MVC 3).  When you install “Preview 1” you will have a new set of ASP.NET MVC 3 project templates show up within Visual Studio 2010’s “New Project” dialog – choosing one of those when you create a new project will cause it to use MVC 3.

    Below are details about some of the new features and capabilities in today’s “Preview 1” release.  Unless otherwise noted, all of the features I describe are enabled with the preview build you can download and use today.  More ASP.NET MVC 3 features will come in future preview refreshes as we flesh out the product more and iterate on your feedback.

    View Improvements

    ASP.NET MVC 3 “Preview 1” includes a bunch of view-specific improvements.

    Add->View Dialog

    “Preview 1” includes a new “Add->View” dialog that makes it easy for you to choose the syntax you want to use when you create new view template files.  It allows you to select any of of the available view engines you have installed on your machine – giving you the ability to use whichever view templating approach feels most natural to you:

    AddView9

    There are a bunch of great open source view template engines out there (including Spark, NHaml, NDjango and more) – it is now much easier for them to integrate into Visual Studio.

    Today’s “Preview 1” build of ASP.NET MVC 3 comes with two view-engine already pre-enabled within the dialog: ASPX and Razor. 

    New “Razor” View Engine

    Earlier this month I blogged about the new “Razor” view engine we’ve been working on.  Based on the comments in the post, a lot of people are eagerly waiting to use it.  The good news is that you can start using it with today’s “Preview 1” release.

    Simple Razor Example

    Let’s build a super-simple store site that lists product categories, and allows visitors to click the categories to see a listing of products within them.  You can download a completed version of this sample here.

    image

    Below is a StoreController class that implements the two action methods (“Index” and “Browse”) needed to build the above scenario:

    image

    We’ll use the new “Razor” view engine to implement the view templates for our StoreController.

    Below is the “Layout.cshtml” layout-page that will define the common layout UI we want across our site.  The “RenderBody()” method indicates where view templates that are based on this master layout file should “fill in” the body content:

    image

    Below is the view template for the Index action.  It is based on the above layout page, and outputs a <ul> list of category names: 

    image

    The template above is using the standard Html.ActionLink() helper method in ASP.NET MVC to render a hyperlink that links to the “Browse” action method of our StoreController.  All of existing HTML helper methods in ASP.NET MVC work in “Razor” views – this is true both for the HTML helper methods built-into ASP.NET MVC, as well as those built by others (including vendors and the MvcContrib project).

    Below is the view template for the Browse action.  It lists the products within a specific category:

    image

    Notice above how we are using the “Model” property within our foreach statement to access the strongly-typed List of products we passed from our Controller.  We are doing this just like we would within .aspx view templates.  Razor also supports a “View” property which allows us to access un-typed “ViewData” passed to the view template.  “View” is a dynamic property (a new feature of .NET 4) – which gives us a slightly cleaner syntax when accessing ViewData.  Instead of writing ViewData[“Cateogry”] we can now just write View.Category.

    Clean and Concise

    The code in the screen-shots above contains everything we need to write to implement our Controller + Views.  “Razor” helps make view templates clean and concise, and I think you’ll find it enables a very fluid coding workflow. Read my “Razor” blog post from earlier in the month to learn more about the syntax and understand how it works.  You can download a running version of the above sample here.

    Code Intellisense and Colorization

    One of the things you might have noticed from the screen-shots above is that “Razor” file colorization and code intellisense is not yet supported in Visual Studio with today’s “Preview 1” release.  We will be enabling full code intellisense and colorization with a future preview refresh.  The VS 2010 editor will support Razor file intellisense for C#/VB code, as well as for HTML/CSS/JavaScript. 

    Other Improvements in the Future

    Three other enhancements we are working to enable in a future preview refresh are:

    • The ability to use a @model statement at the top of a “Razor” file instead of having to explicitly inherit from a base class.  This reduces the code and simplifies it.  
    • The ability to specify a default LayoutPage for the site to avoid having to explicitly set it within each view template.  This further reduces the code within the view template, and makes your code more DRY.
    • The ability to unit-test individual “Razor” template files without having to run the application or launch a web-server.

    With these first two changes the above Browse template will be able to be written as simply:

    image

    The above template syntax will be supported in a future preview refresh.  Full colorization and code-intellisense will be provided within the editor.

    Controller Improvements

    ASP.NET MVC 3 “Preview 1” includes several nice controller-specific enhancements.

    Global Filters

    ASP.NET MVC supports the ability to declaratively apply “cross-cutting” logic using a mechanism called “filters”.  You can specify filters on Controllers and Action Methods today using an attribute syntax like so:

    image

    Developers often want to apply some filter logic across all controllers within an application.  ASP.NET MVC 3 now enables you to specify that a filter should apply globally to all Controllers within an application.  You can now do this by adding it to the GlobalFilters collection.  A RegisterGlobalFilters() method is now included in the default Global.asax class template to provide a convenient place to do this (it is then called by the Application_Start() method):

    image

    The filter resolution logic in MVC 3 is flexible so that you can configure a global filter that only applies conditionally if certain conditions are met (for example: debugging is enabled, or if a request uses a particular http verb, etc).  Filters can also now be resolved from a Dependency Injection (DI) container – more on that below.

    New Dynamic ViewModel Property

    ASP.NET MVC Controllers have supported a “ViewData” property that enables you to pass data to a view template using a late-bound dictionary API.  For example:

    image

    The “ViewData” API is still supported in ASP.NET MVC 3.  MVC 3 augments it, though, with a new “ViewModel” property on Controller that is of type “dynamic” – and which enables you to use the new dynamic language support within VB and C# to pass ViewData items using a slightly cleaner syntax than the current dictionary API.  Now you can alternatively write the following code to achieve the same result as above:

    image

    You do not need to define any strongly-typed classes to use the ViewModel property.  Because it is a “dynamic” property you can instead just get/set properties on it and it will resolve them dynamically at runtime.  It internally stores the property name/value pairs within the ViewData dictionary.

    New ActionResult Types

    ASP.NET MVC 3 “Preview 1” includes several new ActionResult types and corresponding helper methods.

    HttpNotFoundResult

    The new HttpNotFoundResult class is used to indicate that a resource requested by the current URL was not found. It returns a 404 HTTP status code to the calling client. You can optionally use the new HttpNotFound() helper method on Controller to return an instance of this action result type, as shown in the following example:

    image

    Permanent Redirects

    The HttpRedirectResult class has a new Boolean “Permanent” property that is used to indicate whether a permanent redirect should occur. A permanent redirect uses the HTTP 301 status code.  In conjunction with this change, the Controller class now has three new methods for performing permanent redirects: RedirectPermanent(), RedirectToRoutePermanent(), and RedirectToActionPermanent().  These methods return an instance of HttpRedirectResult with the Permanent property set to true.

    HttpStatusCodeResult

    The new HttpStatusCodeResult class can be used to set an explicit response status code and description. 

    JavaScript and AJAX Improvements

    ASP.NET MVC 3 includes built-in JSON binding support that enables action methods to receive JSON-encoded data and model-bind it to action method parameters. 

    To see this feature in action, consider the jQuery client-side JavaScript below.  It defines a “save” event handler that will be invoked when a save button is clicked on the client.  The code within the event handler constructs a client-side JavaScript “product” object with three fields whose values are retrieved from HTML input elements.  It then uses jQuery’s .ajax() method to POST a JSON based request containing the product to a /Store/UpdateProduct URL on the server:

    image

    ASP.NET MVC 3 now enables you to implement the /Store/UpdateProduct URL on the server using an action method like below:

    image

    The UpdateProduct() action method above accepts a strongly-typed Product object as a parameter.  ASP.NET MVC 3 can now automatically bind the incoming JSON post values to the .NET Product type on the server – without you having to write any custom binding or marshalling logic.  ASP.NET MVC’s built-in model and input validation features all work as you’d expect with this.

    We think this capability will be particularly useful going forward with scenarios involving client templates and data binding (like I’ve previously blogged about here).  Client templates will enable you to format and display a single data item or set of data items by using templates that execute on the client.  ASP.NET MVC 3 will enable you to easily connect client templates with action methods on the server that return and receive JSON data.

    Other JavaScript/AJAX Improvements in the Future

    Future preview refreshes of ASP.NET MVC 3 will include better support for unobtrusive JavaScript.  ASP.NET MVC 3 will also directly support the jQuery Validation library from within its built-in validation helper methods.

    Model Validation Improvements

    ASP.NET MVC 2 came with significant model validation improvements.  You can read my previous blog post to learn more about them.

    ASP.NET MVC 3 extends this work further, and adds support for several of the new validation features introduced within the System.ComponentModel.DataAnnotations namespace in .NET 4. In particular:

    • MVC 3 supports the new .NET 4 DataAnnotations metadata attributes such as DisplayAttribute.
    • MVC 3 supports the improvements made to the ValidationAttribute class in .NET 4.  The ValidationAttribute class was improved in .NET 4 to support a new IsValid overload that provides more information about the current validation context, such as what object is being validated.  This enables richer scenarios where you can validate the current value based on another property of the model. 
    • MVC 3 supports the new IValidatableObject interface introduced in .NET 4.  The IValidatableObject interface enables you to perform model-level validation, and enables you to provide validation error messages specific to the state of the overall model, or between two properties within the model. 

    Below is an example of using the IValidatableObject interface built-into .NET 4 to implement a custom validation method on a class.  This method can apply validation rules across multiple properties and yield back multiple validation errors (and optionally include both an error message like below as well as a list of property names that caused the violation):

    image

    ASP.NET MVC 3 now honors the IValidateObject interface when model binding (in addition to all of the other validation approaches it already supported with MVC 2), and will retrieve validation errors from it and automatically flag/highlight impacted fields within a view using the built-in HTML form helpers:

    image

    ASP.NET MVC 3 also introduces a new IClientValidatable interface that allows ASP.NET MVC to discover at runtime whether a validator has support for client validation.  This interface has been designed so that it can be integrated with a variety of validation frameworks.  MVC 3 also introduces a new IMetadataAware interface that simplifies how you can contribute to the ModelMetadata creation process. 

    Dependency Injection Improvements

    ASP.NET MVC 3 provides better support for applying Dependency Injection (DI) and integrating with Dependency Injection/IOC containers.

    In “Preview 1”, we’ve added support for dependency injection in the following places:

    • Controllers (registering & injecting controller factories, injecting controllers)
    • Views (registering & injecting view engines, injecting dependencies into view pages)
    • Action Filters (locating & injecting filters)

    For future previews we are investigating adding dependency injection support for:

    • Model Binders (registering & injecting)
    • Value Providers (registering & injecting)
    • Validation Providers (registering & injecting)
    • Model metadata Providers (registering & injecting)

    ASP.NET MVC 3 will support the Common Service Locator library, and any DI container that supports it’s IServiceLocator interface.  This will make it really easy to integrate any DI container that supports the Common Service Locator with ASP.NET MVC.

    Note: In Preview 1, we redefined the CSL interface in our codebase, and didn’t include the CSL DLL in our setup. This means that existing implementations of CSL won’t “just work” with “preview 1” – instead they’ll have to recompile their CSL implementations against our interface to make them work. Future preview refreshes will make this CSL library dependency easier, and avoid this extra step.

    Brad Wilson is starting a great blog series on ASP.NET MVC 3’s Dependency Injection Support.  Below are links to his first few articles about it:

    Click here to download a simple ASP.NET MVC 3 example that demonstrates how to use the popular Ninject Dependency Injection Container with ASP.NET MVC 3. 

    Downloads and Links

    Click here to download ASP.NET MVC 3 Preview 1.  Post feedback/issues about it in the ASP.NET MVC Forum.

    Once ASP.NET MVC 3 is installed, you can download and run the simple Razor sample I demonstrated in the blog post above. 

    Read my previous “Razor” blog post to learn more about how it works and its syntax.  Also read my recent EF4 Code-First and EF4 Code-First Schema Mapping posts to learn more about the database code and clean model layer I built using EF4 Code-First and SQL Express within the above sample.

    Summary

    We are excited to get today’s ASP.NET MVC 3 “Preview 1” release in people’s hands, and start receiving feedback on it. 

    Our primary goal with these early preview releases is to get feedback – both on what you like/dislike, and what you find missing/incomplete.  This feedback is super valuable – and ultimately makes the final product much, much better.  If you do install today’s “Preview 1” build, please post your feedback and any bugs/issues you find to the ASP.NET MVC forum at http://forums.asp.net.  The team will be monitoring this forum closely, and will be happy to help with anything you run into. 

    We will then iterate on the feedback you send us, and further refine ASP.NET MVC 3 in future preview refreshes.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • VS 2010 Productivity Power Tools Update (with some cool new features)

    Last month I blogged about the VS 2010 Productivity Power Tools Extensions – a free set of Visual Studio 2010 extensions that provide some really nice additional functionality.

    The initial Visual Studio Productivity Power Tools release included a bunch of really useful productivity enhancements – including a much faster “Add Reference” dialog, lots of code editor additions and enhancements, and some nice IDE improvements around document tab management.  You can learn more about these features in my previous blog post.

    VS 2010 Productivity Power Tools Update

    Yesterday we shipped an update to the VS 2010 Productivity Power Tools which adds some nice new features and enhancements.

    If you already have the VS 2010 Productivity Power Tools installed, you can update it to the latest release by choosing Visual Studio’s “Tools->Extension Manager” menu command.  This will bring up the VS 2010 Extension Manager – which allows you to browse and download new extensions.  If you click the “Updates” tab on the left-hand side of the dialog it also allows you to see any updates that are available for extensions you already have installed within your IDE.

    Simply click the “Update” button for the Productivity Power Tools extension and it will download and install an update for it:

    image

    If you don’t already have the VS 2010 Productivity Power Tools installed, you can download and install it here.

    Sean has a nice blog post that describes all of this week’s productivity power tool updates and additions.  Below are a few of the highlights:

    Tools Options Support

    The top feature request with the productivity power tools has been to have the ability to turn on/off individual features and extensions it provides. 

    With last month’s release you couldn’t easily turn individual features on and off.  Starting with this week’s update you can use Tools->Options within VS 2010, and use a new Productivity Power Tools section to easily enable/disable each feature individually:

    image

    In addition to enabling/disabling individual features, you can also tweak/edit their settings (including color schemes and behavior).

    Solution Navigator

    Solution Navigator is a new VS 2010 tool window provided with this week’s update.  It acts like an enhanced Solution Explorer.  It merges functionality from Solution Explorer, Class View, Object Browser, Call Hierarchy, Navigate To, and Find Symbol References all into one tool window – and is pretty darn cool.  Here are just two scenarios of how you can take advantage of it:

    File + Class Explorer in One

    You can use the “Solution Navigator” to browse your project just like you would with the standard “Solution Explorer” tool window today.  Except instead of ending with only file sub-nodes, you can now expand them to see classes as well as individual methods and members within them. Clicking on one of the sub-nodes will navigate you immediately to the appropriate code block within the code editor.

    For example, below we’ve expanded the \Controllers folder within an ASP.NET MVC project and drilled into the AccountController.cs file – which has a AccountController class within it.  We can now drill into that class within the “Solution Navigator” to see a listing of all of its members – and double-click any of them to jump to it within the code editor:

    image

    Filter Solution

    You might have noticed the search box that is at the top of the Solution Navigator above.  You can search within it to quickly filter your solution view. 

    For example, below I’ve entered the string “Log” – which causes the “Solution Navigator” to automatically filter to only show those files and members that contain the word “Log” in their names (everything else is hidden within the explorer).  Notice below how my filtered views displays a “view template” file named “LogOn.cshtml”, the three “LogXYZ” methods within my AccountController class, the LogOnModel class within the AccountModels.cs file, and several tests within my test project whose names contain Log:

    image

    You can double click any of the filtered files or members to immediately navigate to it within the code editor.

    Quick Access

    Quick Access is a new VS 2010 tool window that allows you to quickly search for and execute common tasks within the IDE.  Ever wondered where a particular menu command is located?  Or ever struggled to find a specific option within the Tools->Options dialog?  Just enter it within Quick Access and it will help you locate it:

    image

    Clicking any of the items within the list will execute the command, or take you to the appropriate place in the IDE where it lives (in the case of Tools->Options settings):

    image

    Above I searched for “format” and brought up all the tools->options format settings.  Clicking the “Text Editor->C#->Formatting->New Lines” item within the list opens up the Tools-Options dialog to that exact option location.

    Summary

    I’ve only touched on a few of the improvements with this week’s update.  Read Sean’s blog post for even more details on the updates and improvements.

    If you haven’t installed the free VS 2010 Productivity Power Tools, I highly recommend doing so – I think you’ll find some useful extensions that you’ll like.  If you already have last month’s release installed, you can easily update it to this week’s release to take advantage of even more cool features – as well as benefit from bug fixes and performance improvements.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Code-First Development with Entity Framework 4

    .NET 4 ships with a much improved version of Entity Framework (EF) – a data access library that lives in the System.Data.Entity namespace.

    When Entity Framework was first introduced with .NET 3.5 SP1, developers provided a lot of feedback on things they thought were incomplete with that first release.  The SQL team did a good job of listening to this feedback, and really focused the EF that ships with .NET 4 on addressing it. 

    Some of the big improvements in EF4 include:

    • POCO Support: You can now define entities without requiring base classes or data persistence attributes.
    • Lazy Loading Support: You can now load sub-objects of a model on demand instead of loading them up front.
    • N-Tier Support and Self-Tracking Entities: Handle scenarios where entities flow across tiers or stateless web calls.
    • Better SQL Generation and SPROC support: EF4 executes better SQL, and includes better integration with SPROCs
    • Automatic Pluralization Support: EF4 includes automatic pluralization support of tables (e.g. Categories->Category).
    • Improved Testability: EF4’s object context can now be more easily faked using interfaces.
    • Improved LINQ Operator Support: EF4 now offers full support for LINQ operators.

    Visual Studio 2010 also includes much richer EF designer and tooling support. The EF designer in VS 2010 supports both a “database first” development style – where you construct your model layer on a design surface from an existing database.  It also supports a “model first” development style – where you first define your model layer using the design surface, and can then use it to generate database schema from it.

    Code-First Development with EF

    In addition to supporting a designer-based development workflow, EF4 also enables a more code-centric option which we call “code first development”.  Code-First Development enables a pretty sweet development workflow.  It enables you to:

    • Develop without ever having to open a designer or define an XML mapping file
    • Define your model objects by simply writing “plain old classes” with no base classes required
    • Use a “convention over configuration” approach that enables database persistence without explicitly configuring anything
    • Optionally override the convention-based persistence and use a fluent code API to fully customize the persistence mapping

    EF’s “code first development” support is currently enabled with a separate download that runs on top of the core EF built-into .NET 4.  CTP4 of this “code-first” library shipped this week and can be downloaded here

    It works with VS 2010, and you can use it with any .NET 4 project (including both ASP.NET Web Forms and ASP.NET MVC).

    Step by Step Tutorial: Building NerdDinner using a Code-First Approach

    Last year I wrote an ASP.NET MVC 1.0 tutorial that was published both online and in a book.  The tutorial walked through creating a simple application, called “NerdDinner”, which provides an easy way for people to organize, host and RSVP for dinners online.  You can read my original ASP.NET V1 NerdDinner tutorial here.  An updated version of the tutorial is also included in the new Professional ASP.NET MVC 2 book.

    The NerdDinner tutorial used a “database first approach” where the database schema was defined first, and then we used a Visual Studio designer to create our LINQ to SQL / LINQ to Entities model objects that mapped to it.  

    Below I’m going to demonstrate how we could instead use a “code first approach” using EF4 to build the NerdDinner model layer and database schema, and construct a CRUD application using ASP.NET MVC.

    image

    We will walkthrough building this application step-by-step.  A download link to a completed version of the sample is available at the end of this blog post.

    Step 1: Create a New Empty ASP.NET MVC 2 Application

    We’ll start by creating a new ASP.NET MVC 2 Project within Visual Studio 2010.  Choose File->New Project and use the “ASP.NET MVC 2 Empty Web Application” project template to do this.

    This will create an empty ASP.NET MVC 2 project that does not have any controllers, models or views within it:

    image

    We’ll next work to define our NerdDinner “model” – which refers to the objects that represent the data of our application, as well as the corresponding domain logic that integrates validation and business rules with it.  The model is the "heart" of an MVC-based application, and fundamentally drives the behavior of it.  We’ll create this model layer using the new EF4 “Code First” capabilities.

    Step 2: Create our Model

    Let’s assume we do not already have a database defined, and that we are building our new NerdDinner application completely from scratch.

    We do not need to start with a database

    When using a code-first development workflow, we do not need to begin our application by creating a database or specifying schema.  Instead we can begin by writing standard .NET classes that define the domain model objects that are most appropriate for our application – without having to worry about intermixing data persistence logic within them.

    Creating Model Classes

    NerdDinner is a small application, and our data storage needs with it are pretty simple.  We want to be able to define and store “Dinners” that refer to specific events that people can attend.  We also want to be able to define and store “RSVP” acceptances, which are used to track a person’s interest in attending a particular Dinner.

    Let’s create two classes (Dinner and RSVP) to represent these concepts.  We’ll do this by adding two new classes to our ASP.NET MVC project - “Dinner” and “RSVP”:

    image

    The above “Dinner” and “RSVP” model classes are “plain old CLR objects” (aka POCO).  They do not need to derive from any base classes or implement any interfaces, and the properties they expose are standard .NET data-types.  No data persistence attributes or data code has been added to them. 

    The ability to define model classes without having to tie them to a particular database, database API, or database schema implementation is really powerful – and provides us with much more data access flexibility.  It allows us to focus on our application/business needs without having to worry about persistence implementation.  It also gives us the flexibility to change our database schema or storage implementation in the future – without having to re-write our model objects, or the code that interacts with them.

    Creating a Context Class to Handle Database Persistence

    Now that we’ve defined our two POCO model classes, let’s create a class that we can use to handle the retrieval/persistence of Dinner and RSVP instances from a database. 

    We’ll name this class “NerdDinners”. It derives from the DbContext base class, and publishes two public properties – one that exposes our Dinner objects, and one that exposes our RSVP objects:

    image

    The DbContext and DbSet classes used above are provided as part of the EF4 Code-First library.  You’ll need to add a reference to the System.Data.Entity.CTP assembly that is installed into the \Program Files\Microsoft ADO.NET Entity Framework Feature CTP4\Binaries directory to reference these classes.  You’ll also want to add a “using System.Data.Entity” namespace statement at the top of your “NerdDinners” class file.

    That is all the code we need to write

    The above three classes contain all of the code necessary to implement a basic model and data persistence layer for our NerdDinner application.  We do not need to configure any additional database schema mapping information, nor run any tools, nor edit any XML files, nor use any designers in order to start using our classes to retrieve, update, and save data into a database.

    Convention Based Persistence Mapping

    We do not need to write any additional code, nor create any XML files, nor use any tools in order to map our model classes to and from a database.  How, you might ask, is that possible?

    By default, EF code-first supports a “convention over configuration” approach that enables you to rely on common mapping conventions instead of having to explicitly configure things.  You can override these conventions if you want to provide custom database mapping rules.  But if you instead just use the default conventions you’ll find that the amount of code you have to write is really small, and the common 90% of scenarios “just work” the way you’d expect them to without any extra code or configuration.

    In our example above, our NerdDinners context class will by default map its “Dinners” and “RSVPs” properties to “Dinners” and “RSVPs” tables within a database.  Each row within the Dinners table will map to an instance of our “Dinner” class.  Likewise, each row within the RSVPs table will map to an instance of our “RSVP” class.  Properties within the “Dinner” and “RSVP” classes in turn map to columns within the respective “Dinners” and “RSVPs” database tables.

    Other default conventions supported by EF include the ability to automatically identify primary-key and foreign keys based on common naming patterns (for example: an ID or DinnerID property on the Dinner class will be inferred as the primary key).  EF also includes smart conventions for wiring-up association relationships between models.  The EF team has a blog post that talks more about how the default set of conventions work here.

    Code Examples of How to Use Our Model

    The three classes we created earlier contain all of the code necessary to implement our model and data persistence for NerdDinner.  Let’s now look at a few code examples of how we can use these classes to perform common data scenarios:

    Query Using LINQ Expressions

    We can write LINQ query expressions to retrieve data from a database using the following code.  Below we are using a LINQ expression to retrieve all dinners that occur in the future:

    image

    We can also take advantage of relationships between Dinners and RSVPs when writing our LINQ expressions.  Notice below how our “where” statement filters by dinners whose RSVP count is greater than 0:

    image

    Note that the “where” filter in the above query (where we are retrieving only those Dinners who have at least one RSVP) executes in the database server – making the query and the amount of data we retrieve very efficient.

    Retrieving a Single Instance

    We can use LINQ’s Single() method with a lambda query to retrieve a single instance of a Dinner using code like below:

    image

    Alternatively, we can also take advantage of a Find() method that EF “code-first” exposes that allows you to easily retrieve an instance based on its ID:

    image

    Adding a new Dinner

    The code below demonstrates how to create and add a new Dinner to the database.  All we need to do is to “new” a Dinner object, set properties on it, and then add it to the Dinners property of our NerdDinners context object.  The NerdDinner context class supports a “unit of work” pattern that enables you to add multiple models to the context, and then call “SaveChanges()” on it to persist all of the changes to a database as a single atomic transaction.

    image

    Updating a Dinner

    The code below demonstrates how to retrieve a Dinner, update one of its properties, and then save the changes back to the database:

    image

    Step 3: Create a ASP.NET MVC Controller that uses our Model

    Let’s now look at a more complete scenario involving our model, where we use a controller class to implement the functionality necessary to publish a list of upcoming dinners, and enable users to add new ones:

    image

    We’ll implement this functionality by right-clicking on the “Controllers” folder and choose the “Add->Controller” menu command.  We’ll name our new controller “HomeController”.

    We’ll then add three “action methods” within it that work with the NerdDinners model we created earlier using EF “Code-First”:

    image

    The “Index” action method above retrieves and renders a list of upcoming dinners. 

    The “Create” action methods allow users to add new dinners.  The first “Create” method above handles the “HTTP GET” scenario when a user visits the /Home/Create URL, and send back a “New Dinner” form to fill out.  The second “Create” method handles the “HTTP POST” scenario associated with the form – and handles saving the dinner in the database.  If there are any validation issues it redisplays the form back to the user with appropriate error messages.

    Adding Views for our Controllers

    Our next step will be to add two “View templates” to our project – one for “Index” and one for “Create”. 

    We’ll add the “Index” view to our project by moving our cursor within the Index action method of our controller, and then right-click and choose the “Add View” menu command.  This will bring up the “Add View” dialog.  We’ll specify that we want to create a strongly-typed view, and that we are passing in a IEnumerable list of “Dinner” model objects to it:

    image

    When we click “Add”, Visual Studio will create a /Views/Home/Index.aspx file.  Let’s then add the following code to it – which generates a <ul> list of Dinners, and renders a hyperlink that links to our create action:

    image

    We’ll then add the “Create” view to our project by moving our cursor within the Create action method of our controller, and then right-click and choose the “Add View” menu command.  Within the “Add View” dialog we’ll specify that we want to create a strongly-typed view, and that we are passing it a Dinner object.  We’ll also indicate that we want to “scaffold” using a “Create” template:

    image

    When we click “Add”, Visual Studio will create a /Views/Home/Create.aspx file with some scaffold-generated content within it that outputs an HTML <form> for a “Dinner” object.  We’ll tweak it slightly and remove the input element for the DinnerID property.  Our final view template content will look like this:

    image

    We have now implemented all of the code we need to write within our Controller and Views to implement the Dinner listing and Dinner creation functionality within our web application.

    Step 4: The Database

    We’ve written our code.  Now let’s run the application. 

    But what about the database?

    We don’t have a database yet – and haven’t needed one so far because our “code first” development workflow hasn’t required us to have one to define and use our model classes. 

    But we will need a database when we actually run our application and want to store our Dinner and RSVP objects.  We can create the database one of two ways:

    1. Manually create and define the schema ourselves using a database tool (e.g. SQL Management Studio or Visual Studio)
    2. Automatically create and generate the schema directly from our model classes using the EF Code-First library

    This second option is pretty cool and is what we are going to use for our NerdDinner application.

    Configuring our Database Connection String

    To begin with, we’ll setup a connection-string to point to where we want our database to live.  We’ll do this by adding a “NerdDinners” connection-string entry to our application’s web.config file like so: 

    image 

    By default, when you create a DbContext class with EF code-first, it will look for a connection-string that matches the name of the context-class.  Since we named our context class “NerdDinners”, it will by default look for and use the above “NerdDinners” database connection-string when it is instantiated within our ASP.NET application.

    Taking advantage of SQL CE 4

    You can use many different databases with EF code-first – including SQL Server, SQL Express and MySQL.

    Two weeks ago I blogged about the work we are also doing to enable the embedded SQL CE 4 database engine to work within ASP.NET.  SQL CE 4 is a lightweight file-based database that is free, simple to setup, and can be embedded within your ASP.NET applications.  It supports low-cost hosting environments, and enables databases to be easily migrated to SQL Server.

    SQL CE can be a useful option to use when you are in the early stages of defining (and redefining) your model layer – and want to be able to quickly create and recreate your database as you do so.  We’ll use SQL CE 4 to begin with as we develop our NerdDinner application.  We can later optionally change the connection-string to use SQL Express or SQL Server for production deployment – without having to modify a single line of code within our application.

    The connection-string I specified above points to a NerdDinners.sdf database file, and specifies the SQL CE 4 database provider.  In order for this to work you need to install SQL CE 4 – either via the Standalone SQL CE Installer or by installing WebMatrix (which includes it built-in).  SQL CE 4 is a small download that only takes a few seconds to install.

    Important: In the connection-string above I’m indicating that we want to create the NerdDinners.sdf file within the |DataDirectory| folder – which in an ASP.NET application is the \App_Data\ folder immediately underneath the application directory.  By default the “Empty ASP.NET MVC Web Application” project template does not create this directory.  You will need to explicitly create this directory within your project (right click on the project and choose the “Add->ASP.NET Folder->Add_Data” menu item).

    Automatic Database Schema Creation

    EF code-first supports the ability to automatically generate database schema and create databases from model classes – enabling you to avoid having to manually perform these steps.

    This happens by default if your connection-string points to either a SQL CE or SQL Express database file that does not already exist on disk.  You do not need to take any manual steps for this to happen.

    To see this in action, we can press F5 to run our NerdDinner application.  This will launch a browser at the root “/” URL of our application.  You should see a screen like below rendered back:

    image

    The “/” URL to our application invoked the HomeController.Index() action method – which instantiated and queried our NerdDinners context object to retrieve all upcoming Dinners from our database.  Because the NerdDinners.sdf database file we pointed our connection-string to didn’t already exist, the EF code-first library automatically generated it for us.  It used our NerdDinners context object to automatically infer the database schema for the database it generated. 

    To see the SQL CE database file that was generated, click the “Show all Files” icon within the Visual Studio solution explorer, and then press the “Refresh” button and expand the App_Data folder:

    image 

    We will be shipping an update to VS 2010 in the future that enables you to open up and edit SQL CE 4 databases within the “Server Explorer” tab (just like you do with SQL databases today).  This will enable you to easily see (and optionally tweak) the schema and contents of the database.  Until then you can optionally use the database tools within WebMatrix to examine the SQL CE 4 database file’s contents. 

    We did not specify any custom persistence mapping rules with our NerdDinners context – so the database that was generated followed the default EF code-first naming conventions to map the schema.  If we had specified any custom mapping rules, though, the EF code-first library would have honored those and generated a database that matched them. 

    Just to refresh our memory – here are the two POCO model classes and the NerdDinners context class that we defined earlier:

    image

    Below are the tables that were added when we ran our application and the database was automatically created based on the above model:

    image 

    The definition of the “Dinners” table looks like below.  The column names and data-types map to the properties of the Dinner class we defined.  The DinnerID column has also been configured to be both a primary key and an identity column:

    image

    The definition of the “RSVPs” table looks like below.  The column names and data-types map to the properties of the RSVP class we defined.  The RsvpID column has also been configured to be both a primary key and an identity column:

    image

    A one to many primary key/foreign key relationship was also established between the Dinners and RSVPs tables.  The EF code-first library inferred that this should be established because our Dinner class has an ICollection<RSVP> property named RSVPs, and the RSVP class has a Dinner property.  

    Populating the Database with some Dinners

    Let’s now create and add some Dinners to our database.  We’ll do this by clicking the “Create New Dinner” link on our home-page to navigate to our “Create” form:

    image

    When we click the “Create” button, our new Dinner will be saved in the database.  We can repeat this multiple times to register several different Dinners.  Each new Dinner we create will be persisted within our database and show up in our Home listing of upcoming dinners:

    image 

    Step 5: Changing our Model

    We are going to continually evolve and refactor our model as our application grows.  The EF code-only library includes some nice development features that make it easier to coordinate this evolution with a development database.

    Adding a new Property to the Dinner Model

    Let’s walkthrough making a simple change to our Dinner class.  Specifically, we’ll add an additional property to our Dinner class called “Country”:

    image

    Now that we’ve made this change, let’s press F5 in Visual Studio to build and re-run the application.  When we do this we’ll see the below error message:

    image

    This error message occurs because we’ve changed the structure of our Dinner class, and our model object is now no longer the same shape as the “Dinners” table we automatically created within our database. 

    When EF automatically creates a database for you, it by default adds an “EdmMetadata” table to the database that tracks the shape of the model objects that were used to automatically create the database schema for you: 

    image

    The error message above occurs when EF detects that you’ve made a change to a model object and it is now out of sync with the database it automatically created for you. 

    Re-synchronizing our Model Classes with the Database

    There are a couple of ways we can “re-sync” our model objects and our database:

    • We can manually update our database schema to match our models
    • We can manually delete our database file, re-run the application, and have EF automatically re-create the database
    • We can enable a feature of EF code-first that automatically updates our database for us whenever we change our models

    Let’s look at how we can use this last automatic option with our NerdDinner application.

    The RecreateDatabaseIfModelChanges Feature

    CTP 4 of the EF Code First library includes a useful development-time feature that enables you to automatically re-create your database anytime you make modifications to your model classes.  When you enable it, EF identifies when any of the model classes that were used to automatically create a database are modified, and when that happens can re-create your database to match the new model class shape – without you having to take any manual steps to do so.

    This capability is especially useful when you are first developing an application, since it gives you the freedom and flexibility to quickly refactor and restructure your model code however you want - without having to do any manual work to keep your database schema in sync along the way.  It works especially well with SQL CE – since it is a file-based database that can be dropped and recreated on the fly in under a second.  This can enable an incredibly fluid development workflow.

    The easiest way to enable this capability is to add a Database.SetInitializer() call to the Application_Start() event handler within our Global.asax class:

    image

    This tells EF to re-create our NerdDinners.sdf database to match our NerdDinners model anytime our model classes change shape.  Now when we re-run our application we will no longer get that error message telling us that our model classes and database are out of sync.  EF will instead automatically re-create a database for us that matches our new model class shape, and our application will run fine:

    image

    Seeding Initial Data in Automatically Created Databases

    One of the things you might have noticed in the above screen-shot is that we lost our dinner data when we recreated the database.  This is because the automatic “RecreateDatabaseIfModelChanges” behavior isn’t intended for production scenarios where you want to “migrate” existing data from one schema to another.  Instead it is designed for development scenarios where you want the database to be quickly and automatically updated for you – without you having to take any manual steps or specify migration rules to do so. 

    Note: We are separately working to provide better data migration support for scenarios where you are working with production data and want to version the schema.  We think of that as a different scenario than this early development-time feature that I’m describing here.  The data migration capability isn’t enabled yet with this week’s CTP.

    EF supports the ability for us to optionally “seed” our generated database with default/test data anytime the database is created/recreated.  I find this feature really useful since it enables me to refactor a model, and then quickly run the application to try out a scenario – without having to enter in a bunch of test data manually to do so.

    We can “seed” our NerdDinners database with default data by writing a “NerdDinnersIntializer” class like below.  I’m using it to create two “sample dinners” and adding them to our database like so:

    image

    We can then update the Database.Initializer() call we added to our Global.asax to use this “NerdDinnersInitializer” class at startup:

    image

    And now anytime we make a change to one of our NerdDinner model classes, the database will be automatically dropped and recreated to match our models, and we’ll have two dinners already seeded in the database for testing purposes:

    image

    Easy Refactoring

    The above features make it really easy to evolve and refactor your code at development time – without having to use tools or run scripts to manually keep your database in sync with your code changes.

    Because our model classes, LINQ expressions, and “seed” test data are all strongly typed, we can also take advantage of refactoring tool support inside Visual Studio to quickly and automatically apply changes across our code base in a quick and easy way.

    Step 6: Adding Validation Rules

    We’ve built a nice, simple data-entry application.

    One problem with it, though, is that we don’t currently have any type of input validation in place to ensure that fields are filled out correctly within our Create Dinner form.  Let’s fix that.

    Adding Validation using DataAnnotations

    Validation rules in an ASP.NET MVC based application are usually best expressed within a model.  This enables them to be maintained in a single place, and enforced across any number of controllers and views that might interact with them.  ASP.NET MVC enables you to implement validation rules using a variety of different mechanisms, and is flexible enough to support just about any validation scheme you want to use. 

    ASP.NET MVC 2 includes built-in support for using .NET’s System.ComponentModel.DataAnnotations library of validation rules – which enable you to declaratively apply validation rules to model classes using validation attributes.  You can learn more about this capability in a previous blog post I wrote.  We’ll take advantage of this approach to enable input validation for our NerdDinner application.

    Let’s go back to the Dinner class we defined earlier and add some validation attributes to its properties (note: we need to add a “using System.ComponentModel.DataAnnotations” namespace as well):

    image

    The [Required] validation attribute indicates that a particular property must be specified.  The [StringLength] validation attribute allows us to indicate a maximum length for a particular string property.  The [RegularExpression] validation attribute allows us to indicate that a particular string property must match a specified regular expression in order to be valid – in this case an email address.

    Each of the validation attributes supports an “ErrorMessage” property – which allows us to specify an error message that should be displayed if the validation fails.  This can either be hard-coded as a string (like above) or pulled from a resource – enabling it to be easily localized.

    Referencing some CSS and JavaScript files

    The last step will be to go back to our Create.aspx view template and add a <link> reference to a Site.css file in our project, as well as two <script> elements that reference two JavaScript files in our project.  We’ll also add one line of code to call Html.EnableClientValidation() before our <form> element is rendered:

    image

    These changes will ensure that any validation error messages that are displayed in the page are styled (to make them more visible), and that the validation rules we apply on our model will be applied both on the client and on the server.

    Running the Application

    Let’s re-run the application and try to create a new Dinner.  Let’s begin by pushing the “Create” button with no values filled out.  We’ll find that we now see the validation error messages we applied to our model showing up in the browser:

    image

    Because we enabled client-side validation with ASP.NET MVC (that was the one line of code we wrote above), our error messages will update and change in real-time:

    image

    Notice above how our validation error message changed once our “Title” became longer than 20 characters.  This is because we have a [StringLength] property on our Dinner.Title property that indicates a maximum allowed size of 20 characters.  As we started entering a value within the “HostedBy” textbox, our error message likewise changed from the “[Requred]” error message (which asks you to enter your email address) to the “[RegularExpression]” error message (which is telling us we don’t have a valid email address).

    These validation rules work both within the browser (via JavaScript) and on the server (enabling us to protect ourselves even if someone tries to bypass the JavaScript validation) – without us having to make any changes to our controller class.  The ability to specify these rules once within our model, and have them apply everywhere, is extremely powerful – and will enable us to continue to evolve our application in a very clean way. 

    You can learn more about these ASP.NET MVC 2 Model Validation features and how they work here.

    Download

    Click here to download and run the above NerdDinnerReloaded sample we’ve built in this blog post.  It requires VS 2010 (or the free Visual Web Developer 2010 Express). 

    Important: You must download and install SQL CE 4 on your machine for the above sample to work.  You can download the EF Code-First library here.  Neither of these downloads will impact your machine.

    Summary

    This week’s CTP4 release of the “EF Code-First” functionality provides a pretty nice code-centric way to work with data.  It brings with it a lot of productivity, as well as a lot of power.  In today’s tutorial I focused mostly on some of the new productivity enhancements provided with the CTP4 release.  There are many more scenarios we could drill into including its Fluent API for enabling custom persistence mapping rules, its improved testability support, and other more advanced capabilities.

    You can download this week’s CTP4 release of EF Code-First here.  To learn even more about “EF Code-First” check out these blog posts by the ADO.NET team:

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Windows Phone 7 Developer Tools Beta Released

    Earlier today we shipped the beta of the Windows Phone 7 Developer Tools.  You can download them here.

    What is included in the Windows Phone Developer Tools

    The Windows Phone Developer Tools Beta includes:

    • Visual Studio 2010 Express for Windows Phone – a new free, express edition of Visual Studio 2010
    • Express Blend for Windows Phone – a new free, edition of Blend focused on Windows Phone 7 development
    • Silverlight for Windows Phone 7
    • XNA Game Studio for Windows Phone 7

    Integrated with the development tools is a phone emulator that enables you to easily develop and test Windows Phone 7 applications on your laptop or desktop machine – without requiring a phone device.  It is hardware accelerated, supports multi-touch events on multi-touch capable monitors, and provides a really easy way to debug and try out your phone applications.

    Devices for Developers

    In addition to testing applications within the emulator, we are also this month starting to ship pre-release phones to developers.  You can learn more about this program and sign-up to receive one from this blog post from the Windows Phone 7 team.

    Learning More

    I previously blogged a nice step-by-step tutorial that covers how to build a Twitter search application using Visual Studio 2010 Express for Windows Phone.  It provides a nice introduction on how you can easily use Silverlight and the Visual Studio Tools for Windows Phone to quickly build applications.  You can read and follow the tutorial here.

    Read today’s blog post from the Windows Phone 7 team which provides more details on today’s release. It also mentions two new Silverlight controls – a Panorama and Pivot control - which will enable you to easily implement the new Windows Phone 7 navigation style.  These controls are not implemented in today’s beta, but will be released as an update in a few weeks.

    If you have used the previous Windows Phone 7 CTPs, also make sure to read Jaime’s Migrating Applications from the Windows Phone April CTP Refresh to the Beta blog post.  It provides a wealth of details on how to update code that you’ve already written.

    Uninstalling Previous CTP Bits

    Update: Some people have reported problems with uninstalling the previous CTP of the Windows Phone 7 Developer tools.  Amit has a blog post here that discusses how to fix this. Aaron also has a blog post that discusses how to remove XNA Game Studio in the event that you have a partial install of it that you need to clean up.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • New Embedded Database Support with ASP.NET

    Earlier this week I blogged about IIS Express, and discussed some of the work we are doing to make ASP.NET development easier from a Web Server perspective.

    In today’s blog post I’m going to continue the simplicity theme, and discuss some of the work we are also doing to enable developers to quickly get going with database development.  In particular, I’m pleased to announce that we’ve just completed the engineering work that enables Microsoft’s free SQL Server Compact Edition (SQL CE) database to work within ASP.NET applications.  This enables a light-weight, easy to use, database option that now works great for ASP.NET web development.

    Introducing SQL Server Compact Edition 4

    SQL CE is a free, embedded, database engine that enables easy database storage.  We will be releasing the first public beta of SQL CE Version 4 very shortly. Version 4 has been designed and tested to work within ASP.NET Web applications.

    Works with Existing Data APIs

    SQL CE works with existing .NET-based data APIs, and supports a SQL Server compatible query syntax.  This means you can use existing data APIs like ADO.NET, as well as use higher-level ORMs like Entity Framework and NHibernate with SQL CE.  Pretty much any existing data API that supports the ADO.NET provider model will work with it.

    This enables you to use the same data programming skills and data APIs you know today.

    No Database Installation Required

    SQL CE does not require you to run a setup or install a database server in order to use it.  You can now simply copy the SQL CE binaries into the \bin directory of your ASP.NET application, and then your web application can run and use it as a database engine.  No setup or extra security permissions are required for it to run.  You do not need to have an administrator account on the machine.  It just works.

    Applications you build can redistribute SQL CE as part of them.  Just copy your web application onto any server and it will work.

    Database Files are Stored on Disk

    SQL CE stores databases as files on disk (within files with a .sdf file extension). You can store SQL CE database files within the \App_Data folder of your ASP.NET Web application - they do not need to be registered in order to use them within your application. 

    The SQL CE database engine then runs in-memory within your application.  When your application shuts down the database is automatically unloaded.

    Web Hosting Scenarios Are Now Supported with SQL CE 4

    SQL CE 4 can now run in “medium trust” ASP.NET 4 web hosting scenarios – without a hoster having to install anything. Hosters do not need to install SQL CE or do anything to their servers to enable it.

    This means you can build an ASP.NET Web application that contains your code, content, and now also a SQL CE database engine and database files – all contained underneath your application directory.  You can now deploy an application like this simply by using FTP to copy it up to an inexpensive shared web hosting account – no extra database deployment step or hoster installation required.

    SQL CE will then run within your application at the remote host.  Because it runs in-memory and saves its files to disk you do not need to pay extra for a SQL Server database.

    Visual Studio 2010 and Visual Web Developer 2010 Express Support

    VS 2010 and Visual Web Developer 2010 Express will add SQL CE 4 tooling support for ASP.NET scenarios in an update we’ll be rolling out in the future.  This will enable you to add SQL CE database files to your ASP.NET projects, use the Visual Studio Server Explorer to create and edit tables in them, and use higher-level designers like Entity Framework (see below) to model and map the database to classes that you can then query and program against using LINQ.

    image

    This means that in addition to using the same data APIs you know today, you will also be able to easily use the same development tools you already know with SQL CE.

    Supports Both Development and Production

    SQL CE can be used for both development scenarios and light-usage production usage scenarios.  With the SQL CE 4 release we’ve done the engineering work to ensure that SQL CE won’t crash or deadlock when used in a multi-threaded server scenario (like ASP.NET).  This is a big change from previous releases of SQL CE – which were designed for client-only scenarios and which explicitly blocked running in web-server environments.  Starting with SQL CE 4 you can use it in a web-server as well. 

    There are no license restrictions with SQL CE.

    Easy Migration to SQL Server 

    SQL CE is an embedded database – which makes it ideal for development and light-usage scenarios.  For high-volume sites and applications you’ll probably want to migrate it to use SQL Server Express (which is free), SQL Server or SQL Azure.  These servers enable much better scalability, more development features (including features like Stored Procedures – which aren’t supported with SQL CE), as well as more advanced data management capabilities.

    We’ll ship migration tools that enable you to optionally take SQL CE databases and easily upgrade them to use SQL Server Express, SQL Server, or SQL Azure.  You will not need to change your code when upgrading a SQL CE database to SQL Server or SQL Azure.  Our goal is to enable you to be able to simply change the database connection string in your web.config file and have your application just work.

    Summary

    SQL CE 4 provides an easy, lightweight database option that you’ll now be able to use with ASP.NET applications.  It will enable you to get started on projects quickly – without having to install a full database on your local development box.  Because it is a compatible subset of the full SQL Server, you write code against it using the same data APIs (ADO.NET, Entity Framework, NHibernate, etc).

    You will be able to easily deploy SQL CE based databases to a remote hosting account and use it to run light-usage sites and applications. As your site traffic grows you can then optionally upgrade the database to use SQL Server Express (which is free), SQL Server or SQL Azure – without having to change your code. 

    We’ll be shipping the first public beta of SQL CE 4 (along with IIS Express and several more cool things I’ll be blogging about shortly) next week.

    Hope this helps,

    Scott

  • Introducing IIS Express

    Developers today build and test ASP.NET sites and applications using one of two web-servers:

    • The ASP.NET Development Server that comes built-into Visual Studio
    • The IIS Web Server that comes built-into Windows

    Both of the above options have their pros and cons, and many ASP.NET developers have told us: “I wish I could have the ease of use of the ASP.NET Development Server, but still have all the power and features of IIS”.  Today I’m happy to announce a new, free option that we are enabling – IIS Express - that combines the best characteristics of both, and which will make it easier to build and run ASP.NET sites and applications.

    IIS Express will work with VS 2010 and Visual Web Developer 2010 Express, will run on Windows XP and higher systems, does not require an administrator account, and does not require any code changes to use.  You will be able to take advantage of it with all types of ASP.NET applications, and it enables you to develop using a full IIS 7.x feature-set.

    How Things Work Today

    Before I get into the details of IIS Express, let’s first quickly review how the ASP.NET Development Server and IIS options work today.

    ASP.NET Development Server

    Visual Studio’s built-in ASP.NET Development Server (also known as “Cassini”) has the benefit of being light-weight and easy to quickly run.  It doesn’t listen on remote ports (which makes it easier to get approved for many corporate security environments), works even when you are running under a non-administrator account, and doesn’t require a separate installation step. 

    The fact that it is so easy to get running is a huge positive of it – and the reason it is the default web-server used by ASP.NET projects in Visual Studio when you press F5 to run them:

    image

    The downside with the ASP.NET Developer Server, though, is that it does not support a full set of web-server features.  For example, it doesn’t support SSL, URL Rewriting Rules (like the SEO URL Rewrite Rules I blogged about here), Custom Security Settings, and other richer features now offered with IIS 7.

    IIS Web Server

    IIS is the other option developers use when running and testing their applications with Visual Studio.  You can configure a web project within Visual Studio to use IIS by right-clicking on the project and pulling up its properties (and then by clicking on the “Web” tab within the properties window)":

    image

    Using IIS as your development server allows you to take full advantage of all web-server features (SSL, URL Rewrite Rules, etc).  IIS is a full-fledged web-server – which means you’ll get an experience closer to what it will work like when you deploy the application on a production server.

    The downside with using the IIS option today, though, is that some companies don’t allow full web-servers to be installed on developer machines. IIS also requires administrator account access to setup and debug projects.  Different versions of Windows also support different versions of IIS.  For example, if you are running on Windows XP you have to use the IIS 5.1 web-server that comes with it – which doesn’t support all the new features of IIS 7.x.  Configuring a web project within VS to use IIS also requires some extra installation and configuration steps.

    IIS Express – The Best of Both Options

    We have been working on a new flavor of IIS 7.x that is optimized for developer scenarios that we are calling “IIS Express”. We think it combines the ease of use of the ASP.NET Web Server with the full power of IIS.  Specifically:

    • It’s lightweight and easy to install (less than 10Mb download and a super quick install)
    • It does not require an administrator account to run/debug applications from Visual Studio
    • It enables a full web-server feature set – including SSL, URL Rewrite, Media Support, and all other IIS 7.x modules
    • It supports and enables the same extensibility model and web.config file settings that IIS 7.x support
    • It can be installed side-by-side with the full IIS web server as well as the ASP.NET Development Server (they do not conflict at all)
    • It works on Windows XP and higher operating systems – giving you a full IIS 7.x developer feature-set on all OS platforms

    IIS Express (like the ASP.NET Development Server) can be quickly launched to run a site from a directory on disk.  It does not require any registration/configuration steps. This makes it really easy to launch and run for development scenarios.

    VS 2010 Integration

    We are enabling IIS Express so that it can be easily used with Visual Studio 2010. You’ll be able to configure VS 2010 to use it instead of the ASP.NET Web Server as the default web-server on ASP.NET Projects.  Like the ASP.NET Development Server today, you won’t need to register a site or virtual directory to use IIS Express. It will support the same usage-model as the ASP.NET Development Server today – just with more feature support.

    When you press F5 to run an ASP.NET project, Visual Studio can automatically launch IIS Express and use it to run/debug the application (no extra configuration required).  Like the ASP.NET Web Server, IIS Express will show up in your task-bar tray when running:

    image

    You can right-click and click “exit” on the icon above to quickly shutdown IIS Express.  You can also right-click and pull up a list of all sites running with it, as well as the directory location and .NET versions they are running under:

    image

    Two cool things to notice above:

    1) The “Test Site” we are running, as well as IIS Express itself, live under the c:\users\[username] folder on disk. This enables non-administrator usage of IIS Express and sites – and enables a bunch of scenarios not possible with the full IIS today (including the ability to run IIS Express in both a locked-down enterprise environment as well as a locked-down school shared computer environment).

    2) The “Test Site” we are running above using IIS Express supports both HTTP and HTTPS access.  IIS Express automatically installs a “self-signed certificate” and enables URL ACLs and SSL Certificates for ports so that developers (running as non-administrators on a machine) can use SSL without needing to elevate their accounts or setup any additional configuration.  This enables you to configure secure pages within your applications (like Logon forms) for SSL and run/test them at development time just like they’ll work on your real web-server.

    IIS 7.x Feature Set

    IIS Express is as easy to run and use as the ASP.NET Web Server you are familiar with today.  But because IIS Express is based on the IIS 7x codebase, you have a full web-server feature-set that you can use.  This means you can build and run your applications just they’ll work on a real production web-server.  In addition to scenarios like SSL, you can take advantage of the IIS 7.x URL Rewriter module, Media Extensions, Dynamic Compression, Advanced Logging, Custom Security and other rich modules now available.

    In addition to supporting ASP.NET, IIS Express also supports Classic ASP and other file-types and extensions supported by IIS – which also makes it ideal for sites that combine a variety of different technologies.

    Summary

    We think IIS Express makes it even easier to build, run and test web applications.  It works with all versions of ASP.NET and supports all ASP.NET application types (including obviously ASP.NET Web Forms and ASP.NET MVC applications).  Best of all – you do not need to change any code to take advantage of it.  You’ll be able to optionally use it with all your current projects today.

    We’ll be releasing the first public beta of IIS Express shortly. With the beta you’ll be able to right-click on a file-system folder and have IIS Express launch a web-site based on that file-system location. We’ll also be releasing a patch for VS 2010 and Visual Web Developer 2010 Express later this year that will enable you to automatically launch and use IIS Express in place of VS’s built-in ASP.NET Developer Server.  Future versions of Visual Studio will then ship with this functionality built-in.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Patch for Cut/Copy “Insufficient Memory” issue with VS 2010

    We’ve received several reports of an occasional issue occurring with VS 2010 when developers try and do “Cut” or “Copy” text operations of text.  In some cases VS incorrectly calculates that not enough memory is available (even though there is memory available) and displays the following error message:

    "Insufficient available memory to meet the expected demands of an operation at this time, possibly due to virtual address space fragmentation. Please try again later."

    There is now a public patch available for this issue which you can download and apply here if you are running into it.  More details on the issue can be found on the Visual Studio team blog here.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. You can follow me at: twitter.com/scottgu

  • Visual Studio 2010 Productivity Power Tool Extensions

    Last month I blogged about the Extension Manager that is built-into VS 2010 – as well as about a cool VS 2010 PowerCommands extension that provides some extra features for Visual Studio.  The Visual Studio 2010 Extension Manager provides an easy way for developers to quickly find and install extensions and plugins that enhance the built-in functionality to VS 2010.

    New VS 2010 Productivity Power Tools Release

    Earlier this week Jason Zander announced the availability of a new VS 2010 Productivity Power Tools release that includes a bunch of great new VS 2010 extensions that provide a bunch of cool new functionality for you to take advantage of. 

    You can download and install the release for free here.  Some of the code editor improvements it provides include:

    • Entire Line Highlighting: Makes it easier to track cursor location within the editor
    • Entire Line Selection: Triple Clicking a line in the code editor now selects the entire line (like with MS Word)
    • Code Block Movement: Use Alt+Up/Down Arrow now moves selected code blocks up/down in the editor
    • Consistent Tabs vs. Spaces: Ensure consistent tab vs. space usage across your projects
    • Colorized Parameters: It is now easier to see/identify method parameters
    • Column Guide: You can now add vertical column guidelines to help with text alignment and sizes
    • Align assignments: Makes it easier to line-up multiple variable assignments within your code
    • HTML Clipboard Support: Copy/paste code from VS into an HTML buffer (useful for blogging!)
    • Ctrl + Click Go to Definition: You can now hold down the Ctrl key and click a type to go to its definition

    It also includes several tab management improvements for managing document tabs within the IDE:

    • Show Close Button in Tab Well: Shows a close button in document well for the active tab (like VS 2008 did)
    • Colored Tabs: You can now select the color of each document tab by project or by regex
    • Pinned Tabs: Enables you to pin tabs to keep them always visible and available
    • Vertical Tabs: You can now show document tabs vertically to fit more tabs than normal
    • Remove Tabs by Usage Order: Better behavior when adding new tabs and one needs to be hidden for space reasons
    • Sort Tabs by Project: Tabs can be sorted by project they belong to, keeping them grouped together
    • Sort Tabs Alphabetically: Tabs can be sorted alphabetically

    And last – but not least – it includes a new and improved “Add Reference” dialog:

    image

    This new Add Reference dialog caches assembly information – which means it loads within a second or two (note: the very first time it still loads assembly data – but it then caches it and makes it fast afterwards). The new Add Reference dialog also now includes searching support – making it easier to find the assembly you are looking for.

    You can read more about all of the above improvements in Jason’s blog post about the release.

    New Visualization and Modeling Feature Pack Release

    Earlier this week we also shipped a new feature pack that adds additional modeling and code visualization features to VS 2010 Ultimate.  You can download it here.

    The Visualization and Modeling Feature Pack includes a bunch of great new capabilities including:

    • Web Site Visualization: New support for generating a DGML visualization for ASP.NET projects
    • C/C++ Native Code Visualization: New support for generating DGML diagrams for C/C++ projects
    • Generate Code from UML Class Diagrams: You can now generate code from your UML diagrams
    • Create UML Class Diagrams from Code: Create UML diagrams from existing code bases
    • Import UML from XML: Import UML class, sequence, and use case elements from XMI 2.1 files
    • Custom Validation Layer Rules: Write custom code to create, modify, and validate layer diagrams

    Jason’s blog post covers more about these features as well.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • My VS 2010 and ASP.NET 4 Talks Online

    The past 7 years I’ve done an annual all day event in Arizona – organized by the most excellent Scott Cate (who always does a phenomenal job organizing the event and making it a great one). Earlier this month I visited and presented 4+ hours of content covering VS 2010, ASP.NET 4 and ASP.NET MVC 2. The talks are demo-heavy and show off a ton of new features.

    NextSlide.com – a .NET shop local to Arizona who has a great product for sharing presentations – volunteered to record the talks and publish them for free using their online presentation tool.  The recordings they did turned out really, really great – and their online player (which combines slides + camera of me + demos in one experience) is awesome.  Below you can watch the first two segments of my event – which cover VS 2010 and ASP.NET 4 – for free online using the NextSlide.com player experience.  I’ll post a link to my ASP.NET MVC 2 segment a little later in a separate blog post. 

    If you’ve never seen me present these talks before and are interested in VS 2010 and .NET 4 content then I’d recommend checking them out – as these recordings do a really good job capturing them.

    Part 1 - VS 2010

    This is a 49 minute segment that starts the event and covers a bunch of the new improvements in VS 2010.  You can launch the presentation directly here or watch it inline below.  You can download powerpoint versions of my slides here.

    Part 2- ASP.NET 4

    This 61 minute segment comes next and drills into some of the framework improvements with ASP.NET 4.  It also goes further on some of the web specific tooling improvements in VS 2010 – and towards the end demonstrates some of the great new end-to-end web deployment features provided with VS 2010 (which work for both ASP.NET Web Forms and ASP.NET MVC applications).

    You can launch the presentation directly here or watch it inline below:

    Learning More about VS 2010 and ASP.NET 4

    I’ve been working on a series of blog post about VS 2010 and .NET 4.  Many of the features I covered in my two talks above are described in more detail in posts within the series.  You can read all of them here. I’ll be continuing adding to the series via my blog, so stay tuned for more in-depth posts about a bunch more new features.

    Hope this helps,

    Scott

    P.S. People often ask whether they can re-use the slides+demos I use in my talks for talks of their own.  The answer to this is always absolutely! No need to ask permission. Feel free to re-use all of my slides for talks of your own.

    P.P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Silverlight 4 Tools for VS 2010 and WCF RIA Services Released

    The final release of the Silverlight 4 Tools for Visual Studio 2010 and WCF RIA Services is now available for download

    Download and Install

    If you already have Visual Studio 2010 installed (or the free Visual Web Developer 2010 Express), then you can install both the Silverlight 4 Tooling Support as well as WCF RIA Services support by downloading and running this setup package (note: please make sure to uninstall the preview release of the Silverlight 4 Tools for VS 2010 if you have previously installed that). 

    The Silverlight 4 Tools for VS 2010 package extends the Silverlight support built into Visual Studio 2010 and enables support for Silverlight 4 applications as well.  It also installs WCF RIA Services application templates and libraries:

    image

    Today’s release includes the English edition of the Silverlight 4 Tooling – localized versions will be available next month for other Visual Studio languages as well.

    Silverlight Tooling Support

    Visual Studio 2010 includes rich tooling support for building Silverlight and WPF applications.

    It includes a WYSIWYG designer surface that enables you to easily use controls to construct UI – including the ability to take advantage of layout containers, and apply styles and resources:

    image

    The VS 2010 designer enables you to leverage the rich data binding support within Silverlight and WPF, and easily wire-up bindings on controls.  The Data Sources window within Silverlight projects can be used to reference POCO objects (plain old CLR objects), WCF Services, WCF RIA Services client proxies or SharePoint Lists. 

    For example, let’s assume we add a “Person” class like below to our project:

    image

    We could then add it to the Data Source window which will cause it to show up like below in the IDE:

    image

    We can optionally customize the default UI control types that are associated for each property on the object.  For example, below we’ll default the BirthDate property to be represented by a “DatePicker” control:

    image

    And then when we drag/drop the Person type from the Data Sources onto the design-surface it will automatically create UI controls that are bound to the properties of our Person class:

    image

    VS 2010 allows you to optionally customize each UI binding further by selecting a control, and then right-click on any of its properties within the property-grid and pull up the “Apply Bindings” dialog:

    image

    This will bring up a floating data-binding dialog that enables you to easily configure things like the binding path on the data source object, specify a format convertor, specify string-format settings, specify how validation errors should be handled, etc:

    image

    In addition to providing WYSIWYG designer support for WPF and Silverlight applications, VS 2010 also provides rich XAML intellisense and code editing support – enabling a rich source editing environment.

    Silverlight 4 Tool Enhancements

    Today’s Silverlight 4 Tooling Release for VS 2010 includes a bunch of nice new features.  These include:

    Support for Silverlight Out of Browser Applications and Elevated Trust Applications

    You can open up a Silverlight application’s project properties window and click the “Enable Running Application Out of Browser” checkbox to enable you to install an offline, out of browser, version of your Silverlight 4 application.  You can then customize a number of “out of browser” settings of your application within Visual Studio:

    image

    Notice above how you can now indicate that you want to run with elevated trust, with hardware graphics acceleration, as well as customize things like the Window style of the application (allowing you to build a nice polished window style for consumer applications).

    Support for Implicit Styles and “Go to Value Definition” Support:

    Silverlight 4 now allows you to define “implicit styles” for your applications.  This allows you to style controls by type (for example: have a default look for all buttons) and avoid you having to explicitly reference styles from each control. 

    In addition to honoring implicit styles on the designer-surface, VS 2010 also now allows you to right click on any control (or on one of it properties) and choose the “Go to Value Definition…” context menu to jump to the XAML where the style is defined, and from there you can easily navigate onward to any referenced resources.  This makes it much easier to figure out questions like “why is my button red?”:

    image

    Style Intellisense

    VS 2010 enables you to easily modify styles you already have in XAML, and now you get intellisense for properties and their values within a style based on the TargetType of the specified control.  For example, below we have a style being set for controls of type “Button” (this is indicated by the “TargetType” property).  Notice how intellisense now automatically shows us properties for the Button control (even within the <Setter> element):

    StyleIntellisense

    Great Video - Watch the Silverlight Designer Features in Action

    You can see all of the above Silverlight 4 Tools for Visual Studio 2010 features (and some more cool ones I haven’t mentioned) demonstrated in action within this 20 minute Silverlight.TV video on Channel 9:

    image

    WCF RIA Services

    Today we also shipped the V1 release of WCF RIA Services.  It is included and automatically installed as part of the Silverlight 4 Tools for Visual Studio 2010 setup.

    WCF RIA Services makes it much easier to build business applications with Silverlight.  It simplifies the traditional n-tier application pattern by bringing together the ASP.NET and Silverlight platforms using the power of WCF for communication.  WCF RIA Services provides a pattern to write application logic that runs on the mid-tier and controls access to data for queries, changes and custom operations. It also provides end-to-end support for common tasks such as data validation, authentication and authorization based on roles by integrating with Silverlight components on the client and ASP.NET on the mid-tier.

    Put simply – it makes it much easier to query data stored on a server from a client machine, optionally manipulate/modify the data on the client, and then save it back to the server.  It supports a validation architecture that helps ensure that your data is kept secure and business rules are applied consistently on both the client and middle-tiers.

    WCF RIA Services uses WCF for communication between the client and the server  It supports both an optimized .NET to .NET binary serialization format, as well as a set of open extensions to the ATOM format known as ODATA and an optional JavaScript Object Notation (JSON) format that can be used by any client.

    You can hear Nikhil and Dinesh talk a little about WCF RIA Services in this 13 minutes Channel 9 video.

    Putting it all Together – the Silverlight 4 Training Kit

    Check out the Silverlight 4 Training Kit to learn more about how to build business applications with Silverlight 4, Visual Studio 2010 and WCF RIA Services.

    The training kit includes 8 modules, 25 videos, and several hands-on labs that explain Silverlight 4 and WCF RIA Services concepts and walks you through building an end-to-end application with them. 

    image 

    The training kit is available for free and is a great way to get started.

    Summary

    I’m really excited about today’s release – as they really complete the Silverlight development story and deliver a great end to end runtime + tooling story for building applications. 

    All of the above features are available for use both in VS 2010 as well as the free Visual Web Developer 2010 Express Edition – making it really easy to get started building great solutions.

    Hope this helps,

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Fun Visual Studio 2010 Wallpapers

    Two weeks ago I blogged about a cool new site that allows you to download and customize the Visual Studio code editor background and text colors (for both VS 2008 and VS 2010 version). The site also allows you to submit and share your own Visual Studio color schemes with others.

    Another new community site has recently launched that allows you to download Visual Studio 2010 themed images that you can use for your Windows desktop background.  You can visit the site here: http://vs2010wallpapers.com/  In addition to browsing and downloading Visual Studio themed wallpapers, you can also submit your own into the gallery to share with others.

    [In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

    Browsing Wallpaper Images

    The site has dozens of wallpaper images that you can browse through and choose from.  They range from the cool and abstract:

    image

    To the fun and silly:

    image

    image

    image

    Enabling the Wallpaper Images as your Windows Desktop

    You can zoom in on any image (hover over the image and then click the “zoom” button that appears over it) and then download it to be your Windows desktop image.  If you visit the site using Internet Explorer, you can also zoom in on the image, then right click on the image and choose the “Set as Background” context menu item to enable it as your Windows desktop.

    Note: you want to make sure you download the zoomed-in/high resolution version of the wallpaper to make sure it looks good as the wallpaper on your desktop.

    Hope this helps,

    Scott

  • “Unplugged” Chat with Me this Thursday

    This Thursday (May 13th) I’m going to be doing another online LIDNUG chat session.  The chat will be from 10:00am to 11:30am Pacific Time. You can learn more about it here and join the chat at the appropriate time with this link.

    I do these chats a few times a year and they tend to be pretty fun.  Attendees can listen to me talk live via LiveMeeting, and can submit any questions they want to me.  I then answer as many of them as I can in the 90 minutes. 

    We’ll probably talk a lot about the new features in VS 2010, .NET 4, Silverlight 4, Windows Phone 7, ASP.NET 4 and ASP.NET MVC 2 this week.

    Hope to get a chance to chat with some of you there!

    Scott

    P.S. In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu

  • Pinning Projects and Solutions with Visual Studio 2010

    This is the twenty-fourth in a series of blog posts I’m doing on the VS 2010 and .NET 4 release.

    Today’s blog post covers a very small, but still useful, feature of VS 2010 – the ability to “pin” projects and solutions to both the Windows 7 taskbar as well VS 2010 Start Page.  This makes it easier to quickly find and open projects in the IDE.

    [In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

    VS 2010 Jump List on Windows 7 Taskbar

    Windows 7 added support for customizing the taskbar at the bottom of your screen.  You can “pin” and re-arrange your application icons on it however you want.

    Most developers using Visual Studio 2010 on Windows 7 probably already know that they can “pin” the Visual Studio icon to the Windows 7 taskbar – making it always present.  What you might not yet have discovered, though, is that Visual Studio 2010 also exposes a Taskbar “jump list” that you can use to quickly find and load your most recently used projects as well.

    To activate this, simply right-click on the VS 2010 icon in the task bar and you’ll see a list of your most recent projects.  Clicking one will load it within Visual Studio 2010:

    image

    Pinning Projects on the VS 2010 Jump List with Windows 7

    One nice feature also supported by VS 2010 is the ability to optionally “pin” projects to the jump-list as well – which makes them always listed at the top.  To enable this, simply hover over the project you want to pin and then click the “pin” icon that appears on the right of it:

    image

    When you click the pin the project will be added to a new “Pinned” list at the top of the jumplist:

    image

    This enables you to always display your own list of projects at the top of the list.  You can optionally click and drag them to display in any order you want.

    Cool Keyboard Trick with Windows 7 Jump Lists

    A cool trick that Scott Cate taught me about is the ability to activate Windows 7 jumplists from the keyboard without having to use a mouse.

    Simply press the Windows key + the Alt key + [task tray icon index] and the jump list will appear. For example, above VS 2010 is the 4th program icon from the left on my machine – so if I press the Windows Key + Alt + 4 at the same time then the VS jumplist will appear.  You can then use the up and down arrows on your keyboard to select the project you want to load from the jumplist.

    VS 2010 Start Page and Project Pinning

    VS 2010 has a new “start page” that displays by default each time you launch a new instance of Visual Studio.  In addition to displaying learning and help resources, it also includes a “Recent Projects” section that you can use to quickly load previous projects that you have recently worked on:

    image

    The “Recent Projects” section of the start page also supports the concept of “pinning” a link to projects you want to always keep in the list – regardless of how recently they’ve been accessed.

    To “pin” a project to the list you simply select the “pin” icon that appears when you hover over an item within the list:

    image

    Once you’ve pinned a project to the start page list it will always show up in it (at least until you “unpin” it).

    Summary

    This project pinning support is a small but nice usability improvement with VS 2010 and can make it easier to quickly find and load projects/solutions.  If you work with a lot of projects at the same time it offers a nice shortcut to load them.

    Hope this helps,

    Scott

  • Visual Studio 2010 Extension Manager (and the new VS 2010 PowerCommands Extension)

    This is the twenty-third in a series of blog posts I’m doing on the VS 2010 and .NET 4 release.

    Today’s blog post covers some of the extensibility improvements made in VS 2010 – as well as a cool new "PowerCommands for Visual Studio 2010” extension that Microsoft just released (and which can be downloaded and used for free).

    [In addition to blogging, I am also now using Twitter for quick updates and to share links. Follow me at: twitter.com/scottgu]

    Extensibility in VS 2010

    VS 2010 provides a much richer extensibility model than previous releases.  Anyone can build extensions that add, customize, and light-up the Visual Studio 2010 IDE, Code Editors, Project System and associated Designers.

    VS 2010 Extensions can be created using the new MEF (Managed Extensibility Framework) which is built-into .NET 4.  You can learn more about how to create VS 2010 extensions from this this blog post from the Visual Studio Team Blog.

    VS 2010 Extension Manager

    Developers building extensions can distribute them on their own (via their own web-sites or by selling them). 

    Visual Studio 2010 also now includes a built-in “Extension Manager” within the IDE that makes it much easier for developers to find, download, and enable extensions online.  You can launch the “Extension Manager” by selecting the Tools->Extension Manager menu option:

    image

    This loads an “Extension Manager” dialog which accesses an “online gallery” at Microsoft, and then populates a list of available extensions that you can optionally download and enable within your copy of Visual Studio:

    image

    There are already hundreds of cool extensions populated within the online gallery.  You can browse them by category (use the tree-view on the top-left to filter them).  Clicking “download” on any of the extensions will download, install, and enable it.

    PowerCommands for Visual Studio 2010

    This weekend Microsoft released the free PowerCommands for Visual Studio 2010 extension to the online gallery.  You can learn more about it here, and download and install it via the “Extension Manager” above (search for PowerCommands to find it).

    The PowerCommands download adds dozens of useful commands to Visual Studio 2010.  Below is a screen-shot of just a few of the useful commands that it adds to the Solution Explorer context menus:

    image

    Below is a list of all the commands included with this weekend’s PowerCommands for Visual Studio 2010 release:

    • Enable/Disable PowerCommands in Options dialog
      This feature allows you to select which commands to enable in the Visual Studio IDE. Point to the Tools menu, then click Options. Expand the PowerCommands options, then click Commands. Check the commands you would like to enable.
      Note: All power commands are initially defaulted Enabled.

    • Format document on save / Remove and Sort Usings on save
      The Format document on save option formats the tabs, spaces, and so on of the document being saved. It is equivalent to pointing to the Edit menu, clicking Advanced, and then clicking Format Document. The Remove and sort usings option removes unused using statements and sorts the remaining using statements in the document being saved.
      Note: The Remove and sort usings option is only available for C# documents. Format document on save and Remove and sort usings both are initially defaulted OFF.
    • Clear All Panes
      This command clears all output panes. It can be executed from the button on the toolbar of the Output window.
    • Copy Path
      This command copies the full path of the currently selected item to the clipboard. It can be executed by right-clicking one of these nodes in the Solution Explorer:
      The solution node; A project node; Any project item node; Any folder.
    • Email CodeSnippet
      To email the lines of text you select in the code editor, right-click anywhere in the editor and then click Email CodeSnippet.
    • Insert Guid Attribute
      This command adds a Guid attribute to a selected class. From the code editor, right-click anywhere within the class definition, then click Insert Guid Attribute.
    • Show All Files
      This command shows the hidden files in all projects displayed in the Solution Explorer when the solution node is selected. It enhances the Show All Files button, which normally shows only the hidden files in the selected project node.
    • Undo Close
      This command reopens a closed document , returning the cursor to its last position. To reopen the most recently closed document, point to the Edit menu, then click Undo Close. Alternately, you can use the CtrlShiftZ shortcut.
      To reopen any other recently closed document, point to the View menu, click Other Windows, and then click Undo Close Window. The Undo Close window appears, typically next to the Output window. Double-click any document in the list to reopen it.
    • Collapse Projects
      This command collapses a project or projects in the Solution Explorer starting from the root selected node. Collapsing a project can increase the readability of the solution. This command can be executed from three different places: solution, solution folders and project nodes respectively.
    • Copy Class
      This command copies a selected class entire content to the clipboard, renaming the class. This command is normally followed by a Paste Class command, which renames the class to avoid a compilation error. It can be executed from a single project item or a project item with dependent sub items.
    • Paste Class
      This command pastes a class entire content from the clipboard, renaming the class to avoid a compilation error. This command is normally preceded by a Copy Class command. It can be executed from a project or folder node.
    • Copy References
      This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.
    • Paste References
      This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.
    • Copy As Project Reference
      This command copies a project as a project reference to the clipboard. It can be executed from a project node.
    • Edit Project File
      This command opens the MSBuild project file for a selected project inside Visual Studio. It combines the existing Unload Project and Edit Project commands.
    • Open Containing Folder
      This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node
    • Open Command Prompt
      This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.
    • Unload Projects
      This command unloads all projects in a solution. This can be useful in MSBuild scenarios when multiple projects are being edited. This command can be executed from the solution node.
    • Reload Projects
      This command reloads all unloaded projects in a solution. It can be executed from the solution node.
    • Remove and Sort Usings
      This command removes and sort using statements for all classes given a project. It is useful, for example, in removing or organizing the using statements generated by a wizard. This command can be executed from a solution node or a single project node.
    • Extract Constant
      This command creates a constant definition statement for a selected text. Extracting a constant effectively names a literal value, which can improve readability. This command can be executed from the code editor by right-clicking selected text.
    • Clear Recent File List
      This command clears the Visual Studio recent file list. The Clear Recent File List command brings up a Clear File dialog which allows any or all recent files to be selected.
    • Clear Recent Project List
      This command clears the Visual Studio recent project list. The Clear Recent Project List command brings up a Clear File dialog which allows any or all recent projects to be selected.
    • Transform Templates
      This command executes a custom tool with associated text templates items. It can be executed from a DSL project node or a DSL folder node.
    • Close All
      This command closes all documents. It can be executed from a document tab.

    How to temporarily disable extensions

    Extensions provide a great way to make Visual Studio even more powerful, and can help improve your overall productivity.  One thing to keep in mind, though, is that extensions run within the Visual Studio process (DevEnv.exe) and so a bug within an extension can impact both the stability and performance of Visual Studio. 

    If you ever run into a situation where things seem slower than they should, or if you crash repeatedly, please temporarily disable any installed extensions and see if that fixes the problem.  You can do this for extensions that were installed via the online gallery by re-running the extension manager (using the Tools->Extension Manager menu option) and by selecting the “Installed Extensions” node on the top-left of the dialog – and then by clicking “Disable” on any of the extensions within your installed list:

    image

    Hope this helps,

    Scott

More Posts Next page »

This Blog

Syndication

Powered by Community Server, by Telligent Systems
'