2

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
John Saunders
  • 160,644
  • 26
  • 247
  • 397
ChrisC
  • 1,161
  • 12
  • 26
  • 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 Jan 08 '15 at 14:43
  • 2
    @JohnSaunders While I don't disagree with you, your comment is not helpful. – ChrisC Jan 08 '15 at 14:58
  • He has a point. They just produce simpler code. They're not relating to a website. It is a 'child's toy' that everyone can play with (use it for a simple life, I mean). – CodingSource Jan 08 '15 at 15:02
  • 1
    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 Jan 08 '15 at 15:05
  • 1
    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 Jan 08 '15 at 15:07
  • 2
    Is it ASP.NET websites? Visit the following: https://postsharp4aspnet.codeplex.com/ PostSharp supports natively ASP.NET Web Applications – CodingSource Jan 08 '15 at 15:08

1 Answers1

2

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.

Daniel Balas
  • 1,805
  • 1
  • 15
  • 20
  • Daniel, thanks for the reply. You are not recommending the tool, so it's not _necessary_ for you to say you work on PostSharp, but it might be a good idea. I know you say so in your profile, but maybe also say so in your answer. – John Saunders Jan 08 '15 at 15:53
  • @JohnSaunders I understand that my answer is not recommending something which is close to recommending own product. I would just like to know if you mean that my affiliation should be stated for the same reason as it should be when recommending own product or to improve answer's credibility. Thanks! – Daniel Balas Jan 08 '15 at 17:15
  • I would recommend stating your affiliation in order to make it clear 1) that you know what you're talking about, and 2) that this is not anonymous self-promotion – John Saunders Jan 08 '15 at 17:18
  • @JohnSaunders 2) is a bit weak in this case since I'm saying not to use our old side-project. So the only benefit is that OP will not be mad at us. Anyway thanks for clarification. – Daniel Balas Jan 08 '15 at 17:39
  • @DanielBalas Sorry for the late tagging, as of today, is your answer still accurate ? – Amon Nov 30 '20 at 14:15
  • 1
    @Amon For project-less websites (which IIRC are not creatable from the UI in VS 2017 and later) it is still true. However, all web projects that have csproj/vbproj (.NET or .NET Core) are working as expected (this also didn't change since then). – Daniel Balas Dec 01 '20 at 09:49