Preparing your project for postsharp - sharparchitecture/Sharp-Architecture-Contrib GitHub Wiki

Postsharp aspects have been removed from contrib project and this page remains as a reference for previous versions.

  1. Put PostSharp Into the Tools Folder of Your Project Copy tools\PostSharp*.* from the S#arp Architecture Contrib distribution or source to the tools directory of your project.

  2. Modify Your Projects to Use PostSharp S#arp Architecture Contrib features other than WCF require PostSharp. PostSharp uses a post-compiler process to inject code into your assemblies when needed. You will have to modify each of the project files in your solution to call the PostSharp post-compiler. If you fail to do this, various features of S#arp Architecture Contrib will not work.

    If you have the solution open in Visual Studio, close it. Then open each project file in a plain text editor and look for a line like the following:

     <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    

    Add a line like that shown in the following XML snippet to import the PostSharp targets immediately after the import of Microsoft.CSharp.targets shown above. You will have to change "PathToPostSharp" to the relative path from your project file to the PostSharp folder under tools. For most SharpArch projects this will be "....\tools".

     <Import Project="PathToPostSharp\PostSharp-1.5.targets" />  
    

    The project file should now contain something like the following:

     <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
     <Import Project="..\..\tools\PostSharp\PostSharp-1.5.targets" />
    

    When you re-open your solution in Visual Studio, it will warn you that the project file contains non-standard instructions. Just tell Visual Studio to open the project anyway and make sure to clear the check box that tells Visual Studio to warn you about this next time it opens a project in the current solution.

  3. Pre-Compile(ngen) PostSharp.exe For Best Performance Go to the folder containing the S#arp Architecture Contrib distribution and open the tools\PostSharp folder. Double-click on "ClickToNgen.bat". This will use the .NET ngen utility to compile the .NET assembly into native code and will cache it for later use. This step should be performed once on each machine that will be used to compile your solution. This improves the performance of PostSharp almost 50% so it is quite important.

  4. Add the PostSharp Folder to Source Control The contents of the PostSharp folder under your tools directory should be included in source control.