PostSharp not working on Visual Studio 2015

I have a Visual Studio 2015 solution into which I copied and pasted several PostSharp validation attributes that I have successfully used in a Visual Studio 2013 project.

The project compiles and runs successfully. Unfortunately though unit tests designed to validate my validation attributes fail. From debugging, I found that none of my attributes get triggered. I have verified that the PostSharp package is correctly referencing the project references as well as the .xproj file.

My validation attribute code is like:

using System;
using PostSharp.Aspects;
using PostSharp.Reflection;

namespace Foo.Domain.Model.ValidationAttributes
{
/// <summary>
/// Validates the parameter to strictly not be null (empty and whitespace is valid). Throws a System.ArgumentNullException if assigned a null value.
/// </summary>
[Serializable]
public sealed class NotNullAttribute : LocationInterceptionAspect, ILocationValidationAspect<object>
{
    public NotNullAttribute()
    {
    }

    public override void OnSetValue(LocationInterceptionArgs args)
    {
        Exception ex = ValidateValue(args.Value, args.LocationName, args.Location.LocationKind);

        if (ex != null)
        {
            throw ex;
        }

        args.ProceedSetValue();
    }

    public Exception ValidateValue(object value, string locationName, LocationKind locationKind)
    {
        return value == null ? new ArgumentNullException(locationName, string.Format("The parameter '{0}' may not be null.", locationName)) : null;
    }
}
}

      

My project.json shows the added dependencies:

{
    "version": "1.0.0-*",
    "description": "MyProject Domain Class Library",
    "tags": [ "MyProject" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "PostSharp": "4.1.21",
        "PostSharp.Patterns.Common": "4.1.21",
        "PostSharp.Patterns.Model": "4.1.21"
    },

    "frameworks": {
        "net451": { }
    }
}

      

And my .xproj file shows the added PostSharp target (I checked it on the path):

<Import Project="..\packages\PostSharp\4.1.21\tools\PostSharp.targets" />

It can be seen from the PostSharp documentation that VS2015 is fully supported, but I can't seem to get these aspects to work. Is there anything I need to do to get PostSharp up and running on Visual Studio 2015?

+3


source to share


1 answer


PostSharp does not currently support the new project build system that was introduced with ASP.NET 5 (this is mentioned in the Compatibility page ). When compilation is run "in memory" then the normal MSBuild extension points are not used and PostSharp is not called. You can try to completely build your solution in VS and see if these aspects are applied that way.

The PostSharp team plans to provide support for the new ASP.NET build system in a future release.



UPDATE

A preview of the ASP.NET 5 Connector for PostSharp has been released on GitHub ( https://github.com/postsharp/PostSharp.Dnx ). This will be "work in progress" until the RTM version of ASP.NET 5 is released.

+2


source







All Articles