Can postsharp aspects be used on website projects?

泄露秘密 提交于 2020-12-12 11:39:07

问题


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:


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.



来源:https://stackoverflow.com/questions/27841806/can-postsharp-aspects-be-used-on-website-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!