2
votes

I'm trying to use a PostSharp aspect in a website project in VS2012. It seems to work fine when I set up a web application project, but when I apply the aspect attribute to a method on a page in the website project it compiles and runs fine, but my OnMethodBoundaryAspect never gets hit. I tried setting breakpoints and logging from the aspect methods.

Does PostSharp support website projects? if so, what am I missing?

Please no comments about why I want to use a website instead of a web app. Unfortunately it is a requirement (don't ask).

This is my aspect code (all in vb.net), but like I said, it works fine on a web app project:

Imports PostSharp.Aspects

Namespace TestAopLib

<Serializable>
Public Class AopTester
    Inherits OnMethodBoundaryAspect

    Public Overrides Sub OnEntry(args As MethodExecutionArgs)
        MyBase.OnEntry(args)
        Debug.WriteLine("In OnEntry")
    End Sub

    Public Overrides Sub OnExit(args As MethodExecutionArgs)
        MyBase.OnExit(args)
        Debug.WriteLine("In OnExit")
    End Sub

    Public Overrides Sub OnSuccess(args As MethodExecutionArgs)
        MyBase.OnSuccess(args)
        Debug.WriteLine("In OnSuccess")
    End Sub

    Public Overrides Sub OnException(args As MethodExecutionArgs)
        MyBase.OnException(args)
        Debug.WriteLine("In OnException")
    End Sub

End Class

End Namespace
1
Why would the PostSharp people bother with web site "projects"? They're not projects, and there's nothing else like them. They are child's toys. - John Saunders
@JohnSaunders While I don't disagree with you, your comment is not helpful. - ChrisC
Aspect-oriented programming is not simple. It shouldn't be surprising when tools developed for Visual Studio projects do not work with web site "projects", since they are unique in not having project files. They have been "special" in that way for a decade now. - John Saunders
PostSharp depends on IL weaving (and maybe more), which takes place after the project builds. Web site "projects" do not build. Maybe if you use the pre-compile feature? But when I've used PostSharp, it depended heavily on MSBUILD, a.k.a. the project file, which web site "projects" do not have. They would have to use a totally different mechanism in order to work with web site "projects". - John Saunders
Is it ASP.NET websites? Visit the following: postsharp4aspnet.codeplex.com PostSharp supports natively ASP.NET Web Applications - CodingSource

1 Answers

2
votes

There is a open-source project that achieves exactly this (as also mentioned by CodingSource). However, it was done for PostSharp 2.x and is neither recommended or supported (as stated on project's home page). It would most likely not work with PostSharp 3+ without major issues.

PostSharp is (currently) integrated via MSBuild (as also mentioned by John Saunders), which is not used by website projects.

While in it's core PostSharp is a command-line tool, it gets so much information from MSBuild that it's quite hard to make it work separately (and neither advised nor documented nor supported in the first place).

P.S.: I currently work for PostSharp technologies.