Using the PostSharp MSBuild Task

If you don't want to use the standard PostSharp targets, you can call the PostSharp MSBuild task directly. This task is defined in the PostSharp.MSBuild.dll assembly. The following code snippet imports the PostSharp MSBuild task in your project:

 <UsingTask AssemblyFile="PostSharp.MSBuild.dll"
            TaskName="PostSharp.MSBuild.PostSharp"/>

You can then invoke PostSharp by including the <PostSharp /> element in your MSBuild project file.

The list of properties supported by this task is given in the reference documentation of the PostSharp.MSBuild.PostSharp type.

If you invoke manually the MSBuild task, you will need to understand the concept of PostSharp projects, PostSharp properties, and PostSharp search path.

Note. If you want to avoid the standard PostSharp targets, define the DontImportPostSharp property in your MSBuild projects. This will prevent targets to be inserted in case that they have been globally enabled.

Note. The PostSharp targets for MSBuild do not use the PostSharp MSBuild by default. Indeed, for performance reasons, the command-line utility is used by default. You should compare the performance of the MSBuild task and command-line approaches before making a definitive choice.