Open sandboxFocusImprove this doc

PS0079: Undefined Task in a Configuration File

Severity Error
Reported by PostSharp
Message The task "<Task>" is not defined. Check the name of the element, or add the plug-in that defines the task.

Cause

The PostSharp compiler runs a pipeline of tasks, which PostSharp and its plug-ins define. A configuration file, such as postsharp.config or a .psproj file, can add or configure tasks with a Tasks section, in which the name of each element is the name of a task. PostSharp reports PS0079 when the name of an element, <Task>, matches no task of the loaded plug-ins: the name is misspelled, or the plug-in that defines the task is not loaded. The message points to the element in the configuration file.

PS0079 is also reported, without a location, when a plug-in adds a task to the project programmatically under a name that no plug-in defines.

PostSharp then cannot set up the project and also reports PS0084.

In the following example, the postsharp.config file next to the program configures a task that does not exist.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <Tasks>
    <!-- No plug-in defines a task named Minify. -->
    <Minify />
  </Tasks>
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;

namespace Errors.PS0079_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 PS0084: The project could not be initialized because of the previous errors.
error PS0079: postsharp.config(5,6): The task "Minify" is not defined. Check the name of the element, or add the plug-in that defines the task.

Resolution

  • When the task is not needed, remove its element from the configuration file. Most projects need no Tasks section: the aspects and the packages of PostSharp add the tasks they need.
  • When the name is misspelled, correct it.
  • When the task comes from a plug-in, make sure that the project references the package of the plug-in, or that a Using element of the configuration file loads it.

In the following example, the element of the undefined task is removed.

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.postsharp.org/1.0/configuration">
  <!-- The element of the undefined task is removed. -->
</Project>
using System;
using PostSharp.Aspects;
using PostSharp.Serialization;

namespace Errors.PS0079_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