Now that PostSharp 2.1 CTP 2 is out of the door, I’ll write more about individual new features. Let’s start with something easy: the NuGet package.

The PostSharp nuget contains everything you need to add aspects to an application. So not only does it contain the run-time library PostSharp.dll, but all the stuff you need to build the project, including the Visual Studio Extension.

Adding PostSharp to your application

It has never been easier to add aspects to your code:

1. Open the Add Library Package Reference dialog normally and search for a package named PostSharp. You may have to scroll down a bit because we just uploaded the package.

 

2. Click on Install :), accept license terms.

3. A few seconds after the installation completes, and only the first time you add PostSharp on your machine, PostSharp will ask you if you want to install the Visual Studio Extension (VSX). The VSX is an important help, so we highly recommend you to install it.

 

4. After the VSX has been installed, restart Visual Studio (again, you should do that only once per machine).

You can see a new page in the project properties. It means PostSharp is enabled for this project.

Features

A lot of smart things actually happen behind this apparent simplicity. The installation process will:

  • Add a reference to the proper PostSharp.dll library. Ok, this is obvious, all NuGet packages do that. Currently, the package supports the .NET Framework and Silverlight.
  • Add a reference to PostSharp.targets so that PostSharp kicks in the build process.
  • Remove any reference to a previous version of PostSharp.
  • Check whether a previous version of the VSX is installed, and help you to uninstall it if applicable.

Installation in Source Repository

It has always been possible to install PostSharp into the source repository however, until this version, there were some inconveniences. In version 1.5, PostSharp ran much more slowly from source repository because its libraries were not ngenned. Version 2.0 mitigated this issue by providing a long-running process (pipe server), but you had to use the setup program to use the VSX.

Starting from version 2.1, you can even deploy the Visual Studio Extension (VSX) from the source repository. When a developer runs PostSharp for the first time on his machine, he will see a dialog box asking whether the VSX should be installed. When someone installs a newer version of PostSharp in the source repository, all developers are requested to upgrade the VSX. No administrative privilege is required. Everything happens in the user profile only.

Note that this feature is not bound to NuGet. You get the same if you use the zip distribution instead of the NuGet package.

Summary

NuGet is a very convenient way to install PostSharp. It provides a streamlined experience and does not require administrative privileges. But most importantly, it will allow third-party vendors and OSS projects to handle dependencies to PostSharp in a very easy way. If your project or product ships aspects, make it easy for developers: include PostSharp as a NuGet dependency.

We’re open to remarks and ideas. Please add a comment to the current post or a topic to the support forum.

Happy PostSharping!

-gael

I’m excited to announce the release of PostSharp 2.1 CTP 2, available for download from our web site and from the NuGet gallery. This CTP is mostly feature complete and has zero known bugs. It includes all fixes from the 2.0 branch.

If you’re not on a tight go-to-production schedule, it’s pretty safe to give this version a try now. Unlike with the previous CTP, we will be in “continuous delivery” mode and will be able to release hot fixes very quickly.

So what’s new in PostSharp 2.1? I’ll be blogging about individual features the next days. Here is a short summary:

  • Build-time performance improvement
  • NuGet packaging and improved no-setup experience
  • Extensions to the System.Reflection API
  • Architecture validation (constraints)
  • Support for obfuscation
  • Support for Silverlight 5
  • License management

Build-Time Performance Improvement

Most users will see some improvement in the build-time performance of PostSharp, but for some users it could even mean a 500% speed up. The main reason? We completely rewrote the last step of the PostSharp pipeline: writing the modified assembly back to disk. The previous implementation was based on ILASM, which scaled badly for very large assemblies. The new implementation is fully written in unsafe C# and is probably the fastest available. Other improvements are due to a better utilization of multiple cores, although PostSharp remains largely a single-threaded program. For details about this feature, see our CTP 1 announcement.

This feature is available on all editions of PostSharp.

NuGet Package and Improved No-Setup Experience

PostSharp 2.1 can now be added to your application directly from Visual Studio thanks to NuGet. No need to run a program with elevated privileges. No need to edit your project file if you want to put PostSharp in your source repository. Everything is done by the NuGet package installer.

You can now use the Visual Studio Extension (VSX) even if you don’t want to run the setup program. The first time you (or your colleague) will build a program using PostSharp, a dialog box will ask you whether you want to install the VSX. No elevated privileges needed. When you deploy a new version of PostSharp to the source control, all developers get the updated VSX.

Thanks to NuGet, it will become much easier for vendors and open-source projects to include a dependency to PostSharp. Our friends at Gibraltar Software already uploaded their application monitoring agent, and will soon update it to include the dependency to the PostSharp package.

This feature is available on all editions of PostSharp.

Extensions to the System.Reflection API

How many times did you want to get the list of all classes in your assembly deriving from System.Forms.Control? Sure, you can enumerate all types and build the index yourself, but it’s quite CPU expensive. Since PostSharp already computes this information internally, it seemed natural to expose it to the PostSharp.dll library. The PostSharp.Reflection.ReflectionSearch class offers methods that allow you to search for:

  • All custom attributes of a given type (or derived type);
  • All custom attributes on a given declaration (including those added through MulticastAttribute);
  • All types derived from a given class or implementing a given interface;
  • All methods, fields or types referenced in the body of a given method;
  • All methods using a given method, field or type in their body;
  • All types, methods, fields, properties, events or parameters referencing a given type.

Note that this functionality is only available at build time. This feature is available on the Professional Edition only.

Architecture Validation (Constraints)

Many people used “empty” aspects that just did one thing: validate the code. You now have a better way to validate your code: constraints (namespace PostSharp.Constraints). As aspects, constraints are custom attributes that you put on your code. They contain code that gets executed for every assembly referencing this code. The constraint logic typically queries the current assembly using reflection and the newly introduced reflection extensions, and emit errors or warnings to Visual Studio. Since your code can use LINQ, you have a very powerful toy to play with! PostSharp comes with off-the-self constraints:

  • [Friend], applied to an internal declaration, will raise an error if the declaration is used in a different namespace than the current one. It can be used to enforce isolation of components, and gives a level of visibility that stands between private and internal.
  • [InternalImplements], applied on public interfaces, will raise an error if the interface is implemented in a different assembly. Use this constraint when you need to expose an interface but don’t want the users of your API to implement it, because you want to reserve the right to add new methods to the interface. PostSharp SDK is full of such interfaces that can be consumed but not implemented.
  • [Internal], applied on a public declaration, will raise an error if the declaration is used in a third assembly. It can be used when you don’t want users to reference a part of the API, but have to make it public for technical reasons.

Note that architecture validation is disabled by default. You need to enable it in your project properties (“PostSharp” property page). This feature is available on the Professional Edition only.

Support for Obfuscation

Let me start with a disambiguation: PostSharp does not become an obfuscator with this feature. It just became compatible with some obfuscators.

In previous versions, you could get into serious problems if you tried to use PostSharp and any obfuscator in the same project. PostSharp relied on some metadata references that were broken by the obfuscator because of renaming, so you got runtime exceptions. This is obvious if, for instance, you had a field of type MethodInfo in your aspect. The method name was stored in the serialization stream and the obfuscator did not know how to modify it. There were other less obvious cases with aspects on generic methods.

PostSharp 2.1 can be made aware of obfuscators and write metadata references in a way that obfuscators can understand and modify. But the obfuscator has also to be aware of PostSharp.

We implemented support for Dotfuscator because it is the market leader and has a free edition that ships with Visual Studio. According to the feedback we get from this CTP, we will publish our specification so that other vendors can implement it if they are interested.

This feature is available on the Professional Edition only.

Support for Silverlight 5 Beta

PostSharp 2.1 supports Silverlight 5 applications. What to add? This feature is available on all editions.

License Management

First of all, we chose to rename the community edition to Starter Edition. We got too many questions whether the community edition can be used for commercial project. We hope the new name makes the answer clear: yes, you can use the Starter Edition in commercial projects, you will just enjoy less features than with the Professional Edition.

At SharpCrafters, our license enforcement policy is to trust the customer to respect the license agreement. That’s why there was no license enforcement in version 2.0. It was not just a priority. But we may have been too liberal by letting people deploy the license key in the source control: for many companies, it meant that nobody knew how many developers were using the product. We strongly believe in trust, but we think that we should provide tools for proper license management. So we did a few changes.

We chose to deprecate deployment of license keys through source control because we want some mental process to take place when a developer first starts using the product: he also needs a license. We provide a license metering solution: we will monitor how many people install the license on their computer, but we will never block them. If we that believe a license key is being used too many times, we will simply contact the one who purchased the license key and discuss a solution. But we trust you in first place. By requesting license installation by each user, we are just asking that every company maintains a record of who is using the software.

What if manual license bookkeeping is impractical? For these situations, we provide a license server (technically: a simple ASP.NET application backed by an SQL database). The license server maintains the list of leases and ensures that the license agreement is respected. It will send emails to the license administrator (or team leader, or whomever else) when new licenses should be acquired – and you will get a 30-day grace period to purchase them. We tried to make the license server a valuable tool for the customer. You are free to modify the underlying database at will if it makes sense. You as the customer are responsible for respecting the legal agreement and we trust you.

The license server will be available with a new type of licenses called corporate licenses, that will be available for a premium (likely +30% compared to the normal commercial license).

Upgrade Today

The upgrade is free for anyone. I am pretty confident of the quality of this release so it’s a great time for you to download it. Submit all your changes to source control, do the upgrade, rebuild, and run your unit tests. If it fails, shelve the changes and report the issue. We do a lot of internal testing, but we need your feedback to move quality of this release forward.

In the next days, I’ll try to blog about individual features of this release.

Happy PostSharping!

I’m excited to kick off the PostSharp speaking tour, which will give me 8 speaking opportunities in the next 2 months.

Developer! Developer! Developer!

My first stop will be Glasgow, Scotland on Saturday May 7 at DDD Scotland 2011. I’ll be in town from Friday evening to Sunday afternoon and there’ll be plenty of opportunities to meet up. I’m happy that the community wants (and voted) to hear more about aspect-oriented development. And yes – even if running SharpCrafters takes a lot of dedication, I still feel myself a developer above all, and am still very reluctant to use the term CEO (which I find inadequate for small companies anyway).

Belgium

As a prelude to the speaking tour, I did a 3-stop trip to Belgium. On March 7th, I presented aspect-oriented programming in a (quite) non-technical way at La journée agile. This was a great event, and was my first public speaking in my native tongue since university! The audience was mainly composed of managers. The day after, I did a second presentation in French for DotNetHub. The recording is available here. Finally, on March 11th, I presented AOP to VISUG, but this time in English. Special thanks to Pierre-Emmanuel for securing these events.

After Glasgow, I’ll have one week in office where some of you will learn more about the next CTP.

Germany

During the week of May 18th, I will literally tour Germany (by train) and visit local user groups. This week will be crazy: Regensburg on Monday, Munich on Tuesday, Ulm on Wednesday, and Karlsruhe on Thursday. And now the worse: a 12 hour night trip by train to get back home in second-class day coach.

Since Germany cannot be toured in one week, I continue on June 6th with a visit of the Hamburg user group on Monday and Cologne on Tuesday.

We wanted to continue the tour, but had to cancel the next stops to fight directly to a first-class conference:

NDC, Oslo

Developers want to hear about AOP. And AOP is not just me: there will be a whole track on AOP and IoC at NDC 2011, featuring (Day 3, Track 5):

  • 9h00: Produce Cleaner Code with Aspect Oriented Programming (me)
  • 10:20: Advanced Aspect Oriented Programming (Donald Belcham)
  • 11:40: Ten Simple Rules for Rewriting IL on the CLR (Philip Laureano, author of LinFu)
  • 13:40: Inversion of Control containers: patterns and anti-patterns (Krzysztof Kozmic, maintainer of Castle DynamicProxy)

And because so many evangelist of different AOP churches, we organized a discussion panel on Day 2, moderated by Carl Franklin and Richard Campbell of .NET Rocks!

If you will be NDC, be sure to attend the panel, and prepare your sharpest questions!

Back home

I’ll be home most of the summer and the autumn, assisting my wife as we and our 3 kids are expecting the delivery of twins for September.

A single exception: I’ll be at the See# Party in Switzerland on August 19th to make sure I reached absolutely all German speakers (Kreuzlingen is at the border between Austria and Switzerland).

Special thanks to Britt, our community dude, for organizing these speaking engagements while I am coding.

More

Twelve speaking engagements in a semester is a lot, but it’s not enough to spread the word to everybody. Fortunately, I’m not the only AOP speaker on earth. Our friends Marcus King, Marko Apfel, Donald Belcham and Matthew Groves are doing good work too. Check our community page to find an event in your region. And of course, if you want to be a speaker too, we can offer you free consulting and materials to help you get started.

Happy PostSharping!

-gael