As the title suggests, i have a problem reusing a custom aspect. I've created a very simple aspect (netstandard2.0) in a project called Postsharp.Why (Referencing nuget PostSharp 6.7.9-rc)
namespace Postsharp.Why
{
using System.Threading.Tasks;
using PostSharp.Aspects;
using PostSharp.Serialization;
[PSerializable]
public class ReasonAttribute : MethodInterceptionAspect
{
private string _reason;
public ReasonAttribute(string reason = "i fail to see")
{
this._reason = reason;
}
public sealed override void OnInvoke(MethodInterceptionArgs args)
{
args.ReturnValue = _reason;
}
public sealed override async Task OnInvokeAsync(MethodInterceptionArgs args)
{
args.ReturnValue = _reason;
}
}
}
Additionally i have created two further tests (xunit) projects
- Postsharp.Question.Test.Fails default project setup + projectreference to Project.Why and
- Postsharp.Question.Test.Works additionally references same Postsharp version.
Code:
namespace Postsharp.Question.Test.Works
{
using Postsharp.Why;
public class Test_PostSharp_Aspects
{
[Reason("!")]
private string foooooo()
{
return "?";
}
[Fact]
public void Test_ShouldReturn_Exclamation()
{
Assert.Equal("!", foooooo());
}
}
}
Note that all projects compile just fine, there is no error. As the name suggests, in the Fail-project the aspect does not work, and i would like to know how i can make it run (without adding the reference), or how i could point out that the used aspect won't run to anyone using that library. If this is not possible, i would like to know how i can enforce that anyone using the Postsharp.Why project can be enforced to install that package?
Thanks in advance!