Project Description

This projects add support for PostSharp 2.0 to ASP.NET Web Sites.

PostSharp supports natively ASP.NET Web Applications, so why would you need a plug-in for ASP.NET Web Sites?

Because ASP.NET Web Sites are not built using MSBuild, but using ASP.NET's own build pipeline. This pipeline allows developers to specify an assembly post-processor, i.e. a "filter" that can enhance the output of the C# or ASP.NET compiler.

Why should you AVOID using PostSharp with ASP.NET Web Sites?

SharpCrafters recommend you avoid using PostSharp in ASP.NET Web Sites. The current project is fully unsupported. Why?
  1. Performance issues: You probably don't want to load the CPU of your build server by an extra build step. Remember that PostSharp is about 10x slower than the C# compiler itself. If you want your web sites to start in reasonable time on web servers (where CPU is usually scarce), refrain for using PostSharp this way. Workaround: use precompiled web sites.
  2. Licensing issues: PostSharp is licensed for uses by developers. PostSharp does not offer a single license for use on web servers. If you're using PostSharp on a web server, you're probably breaking the license agreement. Workaround: use precompiled web sites.
  3. Functionality issues: Unlike ASP.NET Web Applications, which are built into a single assembly, the ASP.NET Web Sites build pipeline breaks a single web site into multiple small assemblies. This may break some PostSharp functionalities.

Bottom line: avoid using PostSharp with ASP.NET Web Sites and, if you can't, deliver only precompiled web sites.

What if I want to use PostSharp with ASP.NET anyway?

That's cool! There are plenty of excellent reasons to use PostSharp with ASP.NET. The only issue is that you should not use PostSharp with that stuff called ASP.NET Web Sites in Visual Studio, that kind of projects that get built by the web server.
  1. You can use ASP.NET Web Projects, which get built by MSBuild as any C#/VB project.
  2. You can put your complex logic in a class library, use aspects in this class library, and use that logic from the ASP.NET Web Site.
  3. You can use this project, but you have been warned.

Quick Start

Build the project PostSharp.AspNet and copy the file PostSharp.AspNet.dll to the bin folder of your ASP.NET Web Site.

Then open the file web.config, locate or add the element /configuration/system.web/compilation, and add the attribute assemblyPostProcessorType="PostSharp.AspNet.AssemblyPostProcessor, PostSharp.AspNet".

    <compilation assemblyPostProcessorType="PostSharp.AspNet.AssemblyPostProcessor, PostSharp.AspNet"/>

The default configuration expects that an environment variable named POSTSHARP20 points to the directory where PostSharp is installed. This environment variable is set by the setup program.

Advanced Configuration

The assembly post-processor does nothing else than invoking the PostSharp command-line utility with the proper parameters. You can influence the way this command line is created by creating a new configuration section in web.config:

    <section name="postsharp" type="PostSharp.AspNet.PostSharpConfiguration, PostSharp.AspNet"/>
 <postsharp directory="C:\svn\postsharp\branches\2.0\Build\bin\Debug" tracecategories="AssemblyBinder"/>
    <compilation debug="true" assemblyPostProcessorType="PostSharp.AspNet.AssemblyPostProcessor, PostSharp.AspNet"/>
    <trace enabled="true" pageOutput="true"/>

For more information about configuration settings, see the source code of the class PostSharpConfiguration.

Last edited Apr 19, 2010 at 1:44 PM by gfraiteur, version 3