| Severity | Warning |
| Reported by | PostSharp |
| Message | The project "<Project>" does not contain any aspect or other transformation. You can disable PostSharp for this project by setting the SkipPostSharp MSBuild property to True or by removing the reference to the PostSharp package. Remember to enable PostSharp again if you add an aspect to this project. |
Cause
PostSharp runs after the C# compiler on every project that references the PostSharp package, directly or through another package. Before it transforms the assembly, PostSharp looks for what it has to do: the types of PostSharp and of the referenced assemblies that the project uses and that require a task of PostSharp, such as aspects or architecture constraints, and the plug-ins that the configuration loads. When it finds nothing, and the assembly does not provide inherited aspects to other assemblies, PostSharp reports PS0131 on the project: the build spends time running PostSharp for no result.
<Project> is the file name of the assembly being built. Defining an aspect class without applying it anywhere does not cause PS0131, because the aspect class itself uses PostSharp.
Unlike other warnings, PS0131 is not escalated to an error by the TreatWarningsAsErrors MSBuild property, only when you list it in WarningsAsErrors. See Ignoring and Escalating Warnings.
In the following example, the project references PostSharp but uses none of its features.
using System;
namespace Errors.PS0131_Error;
// PostSharp processes this project, but nothing in it uses an aspect.
public class OrderService
{
public void SubmitOrder() => Console.WriteLine( "Order submitted." );
}
public static class Program
{
public static void Main()
{
new OrderService().SubmitOrder();
}
}
warning PS0131: The project "PS0131_Error.exe" does not contain any aspect or other transformation. You can disable PostSharp for this project by setting the SkipPostSharp MSBuild property to True or by removing the reference to the PostSharp package. Remember to enable PostSharp again if you add an aspect to this project.
Resolution
When the project does not need PostSharp, remove its reference to the PostSharp package. When the reference comes through another package, or when you want to keep it, set the
SkipPostSharpMSBuild property in the project file instead:<PropertyGroup> <SkipPostSharp>True</SkipPostSharp> </PropertyGroup>Remove the property when you add an aspect to the project: otherwise the aspect is silently not applied.
When you expected an aspect in the project, check that it is applied: an aspect class that is defined but never used as an attribute, multicast or provided does nothing.
When you prefer to keep PostSharp running, for example because aspects are about to be added, ignore the warning with the
PostSharpDisabledMessagesMSBuild property:<PostSharpDisabledMessages>PS0131</PostSharpDisabledMessages>.
In the following example, the @DisabledMessages directive of the test framework of this documentation does what PostSharpDisabledMessages does in a project file.
// @DisabledMessages(PS0131)
using System;
namespace Errors.PS0131_Fixed;
// The directive above suppresses the warning, as PostSharpDisabledMessages does in a project file.
public class OrderService
{
public void SubmitOrder() => Console.WriteLine( "Order submitted." );
}
public static class Program
{
public static void Main()
{
new OrderService().SubmitOrder();
}
}
Order submitted.
See Also
Other Resources
Well-Known MSBuild Properties
Ignoring and Escalating Warnings
Configuring Projects in Visual Studio