| Severity | Error |
| Reported by | PostSharp |
| Message | Task "<Task>": the required attribute "<Attribute>" is missing. |
Cause
A configuration file, such as postsharp.config or a .psproj file, can configure the tasks of the PostSharp compiler with a Tasks section: each element names a task, and its attributes set the properties of the task. An element replaces the configuration that PostSharp gives the task by default, so it must set every property that the task requires. PostSharp reports PS0082 for each required property, <Attribute>, that the element of the task <Task> does not set or sets to an empty string.
Among the tasks of PostSharp, the Compile task, which writes the woven assembly, has a required attribute: TargetFile, the path of the woven assembly.
PostSharp then cannot set up the project and also reports PS0084.
In the following example, the postsharp.config file next to the program configures the Compile task without TargetFile.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<Tasks>
<!-- The required TargetFile attribute is missing. -->
<Compile IntermediateDirectory="{$IntermediateDirectory}" />
</Tasks>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0082_Error;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
error PS0082: Task "Compile": the required attribute "TargetFile" is missing.
error PS0084: The project could not be initialized because of the previous errors.
Resolution
- Remove the element of the task, and the
Taskssection, from the configuration file, unless you need to change the configuration of the task. PostSharp then configures the task itself. - When you keep the element, add the missing attribute. For the
Compiletask, setTargetFileto{$Output}, the path that the build expects.
In the following example, the Compile element sets TargetFile.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
<Tasks>
<!-- TargetFile gives the path of the woven assembly. -->
<Compile TargetFile="{$Output}"
IntermediateDirectory="{$IntermediateDirectory}" />
</Tasks>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;
namespace Errors.PS0082_Fixed;
[PSerializable]
public class LogAttribute : OnMethodBoundaryAspect
{
public override void OnEntry( MethodExecutionArgs args )
{
Console.WriteLine( $"Entering {args.Method.Name}." );
}
}
public class OrderService
{
[Log]
public void PlaceOrder( string product )
{
Console.WriteLine( $"Order placed for {product}." );
}
}
public static class Program
{
public static void Main()
{
new OrderService().PlaceOrder( "Coffee" );
}
}
Entering PlaceOrder.
Order placed for Coffee.
See Also
Other Resources
Configuring Projects Using postsharp.config
Configuration File Schema Reference