Because PostSharp 2 not announced yet, not available PostSharp installer for Visual Studio 2010. I found a blog entry which contains the instructions for using PostSharp without installing via MSI but it not works on VS 2010.
The first problem was the NullPointerException while building with PostSharp. After I googled that I found something useful. This is a known problem by PostSharp’s developers and the solution is the modify project file:
<PropertyGroup>
<PostSharpUseCommandLine>true</PostSharpUseCommandLine>
</PropertyGroup>
There is a possible memory leak in PostSharp execution and the "PostSharUseCommandLine=True" forces PostSharp to use command-line utility. "A new process will be created for each invocation, so there can be surely be no memory leak in this time."
The second was that the PostSharp compiler does not work with .NET 4 assemblies at this moment (PostSharp 1.5). So you will downgrade your PostSharp enabled projects .NET version to 3.5. :(
The modified C# project file:
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>10.0.20506</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{AE544EFB-2842-4A41-BF6C-3038D2046E90}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bes.Core</RootNamespace>
<AssemblyName>Bes.Core</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
...
<PropertyGroup>
<PostSharpUseCommandLine>True</PostSharpUseCommandLine>
<DontImportPostSharp>True</DontImportPostSharp>
<PostSharpDirectory>..\..\libs\PostSharp</PostSharpDirectory>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(PostSharpDirectory)\PostSharp-1.5.targets" />