| Severity | Error |
| Reported by | PostSharp |
| Message | The plug-in "<PlugIn>" required by "<Declaration>" was not found. |
Cause
A library can require that the projects that use it are processed by PostSharp, and by a given plug-in of PostSharp, with RequirePostSharpAttribute. This custom attribute is applied to an attribute class, or to another declaration, of the library: when a project uses this attribute, PostSharp loads the plug-in that PlugIn names and adds the task that Task names. The pattern libraries of PostSharp use this mechanism to add their weavers.
PostSharp reports PS0052, and stops building the project, when it cannot find the plug-in <PlugIn> in its search path. <Declaration> is the declaration of the referenced library that carries the RequirePostSharpAttribute. The usual causes are:
- The plug-in comes with a NuGet package that the project does not reference, for example because the project references the library, but not the package that contains its weaver.
- The packages of the library and of its plug-in have different versions.
- The name of the plug-in is misspelled in the RequirePostSharpAttribute.
PostSharp does not report the message for the declarations of the project itself, only for those of the libraries that it references.
In the following example, the [Audited] attribute of a library requires the Acme.Auditing.Weaver plug-in, which is not available to the project.
// @DisabledMessages(PS0131)
using System;
using PostSharp.Extensibility;
namespace Errors.PS0052_Error.Auditing;
// The library requires a plug-in that is not available to the projects that use the attribute.
[RequirePostSharp( "Acme.Auditing.Weaver", "ValidateAnnotations" )]
[AttributeUsage( AttributeTargets.Method )]
public sealed class AuditedAttribute : Attribute
{
}
using System;
using Errors.PS0052_Error.Auditing;
namespace Errors.PS0052_Error;
public class OrderService
{
// The Audited attribute of the library requires the Acme.Auditing.Weaver plug-in.
[Audited]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error PS0052: The plug-in "Acme.Auditing.Weaver" required by "Errors.PS0052_Error.Auditing.AuditedAttribute" was not found.
Resolution
- Add to the project the NuGet package that contains the plug-in, with the same version as the package of the library. The documentation of the library names this package.
- When the plug-in is in a directory of your source tree, add this directory to the search path of PostSharp with the
PostSharpSearchPathMSBuild property, or with aSearchPathelement inpostsharp.config. See Well-Known MSBuild Properties and Configuration File Schema Reference. - When you develop the library, give the name of the plug-in assembly without its extension. When the task is a task of PostSharp itself, such as the task of the aspect weaver, pass
nullas the name of the plug-in.
In the following example, the library requires only the ValidateAnnotations task, which is part of PostSharp, and the project builds.
// @DisabledMessages(PS0131)
using System;
using PostSharp.Extensibility;
namespace Errors.PS0052_Fixed.Auditing;
// The task is built into PostSharp, so the library does not require any plug-in.
[RequirePostSharp( null, "ValidateAnnotations" )]
[AttributeUsage( AttributeTargets.Method )]
public sealed class AuditedAttribute : Attribute
{
}
using System;
using Errors.PS0052_Fixed.Auditing;
namespace Errors.PS0052_Fixed;
public class OrderService
{
// The Audited attribute of the library now requires only a task of PostSharp.
[Audited]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Order placed for Coffee.
See Also
Reference
Other Resources
Configuration File Schema Reference
Well-Known MSBuild Properties