| Severity | Error (fatal: the build stops) |
| Reported by | PostSharp |
| Message | Error while processing dependencies of the task "<Task>": the task type or service "<Dependency>" could not be found. |
Cause
PostSharp processes an assembly with a set of tasks, defined by task types. PostSharp itself defines the built-in task types, and each plug-in of PostSharp, such as the weavers of the PostSharp Patterns libraries, adds its own. A task type can require other tasks:
- A
Dependencyelement of aTaskTypeelement, or a dependency that the class of the task declares, names another task type, which PostSharp adds to the project. When the project has no task type of this name, PostSharp reports PS0041 and<Dependency>is the name of the task type. - A field of the class of the task can import a service. When the service is not present yet, PostSharp adds the task types that export it. When no task type exports it, PostSharp reports PS0041 and
<Dependency>is the name of the interface of the service.
<Task> is the task that has the dependency. The error is fatal: the build stops at this point.
In practice, PS0041 means that a plug-in requires a task type or a service of another plug-in that PostSharp did not load, or of a version of PostSharp that is not the one of the build: the plug-ins of a project come from its PostSharp packages, and every PostSharp package of a project must have the same version.
This message requires a task type of a plug-in of PostSharp, which the samples of this documentation cannot provide, so no example can show it.
Resolution
- Make sure that every PostSharp package of the project, and of the projects that it references, has the same version, then restore the packages and rebuild.
- When the task with the dependency belongs to a plug-in of your own, or to a
TaskTypeelement of apostsharp.configor.psprojfile, add a reference to the package or the plug-in that defines<Dependency>, or correct the name of the task type in theDependencyelement. - When
<Dependency>is a dependency that the task can do without, set theRequiredattribute of theDependencyelement tofalse.
To see which task types PostSharp knows when it resolves the dependency, capture the trace with the TaskResolving category of the PostSharpTrace MSBuild property, for example:
dotnet build -p:PostSharpTrace=TaskResolving -p:PostSharpUsePipeServer=False --no-incremental -v:detailed > trace.log
See Also
Other Resources
Well-Known MSBuild Properties
Configuring Projects Using postsharp.config