Schlagwort-Archive: PostSharp

How to get the PostSharp package running with Paket

Recently, I reported some difficulties that I‘ve experienced with the PostSharp NuGet package when I was using the new package manager Paket. I tracked the problem down to the ‚install.ps1‘ script which is executed by NuGet after adding PostSharp to a project. This PowerShell script (located under packages\PostSharp\tools) patches your project file. Since this behaviour is already proclaimed from the pulpit by NuGet, I hope that PostSharp is going to remove that asap. Until then, you can execute the script manually or patch the csproj-File by yourself.

In order to do that, insert the following 2 snippets at the the position shown in the screenshots:

   1: <DontImportPostSharp>True</DontImportPostSharp>

 

image

 

Don’t forget to change the relative path to your PostSharp package in the following snippet:

   1: <Import Project="..\..\packages\PostSharp\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp\tools\PostSharp.targets')" /> 

   2: <Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">

   3: <Error Condition="!Exists('..\..\packages\PostSharp\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://www.postsharp.net/links/nuget-restore." />

   4: <Error Condition="Exists('..\..\packages\PostSharp\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />

 

image

 

I also recommend you to activate the following PostSharp Option in Visual Studio:

image

Werbung

PostSharp reports broken references when using Paket

If you use Paket instead of NuGet (why? therefore!) you will experience the following difficulties:

imageGiven is the following Solution/Project. It contains a paket.references file containin just one line “PostSharp”, which is

The PostSharp Assembly is added when you your “paket.references” file in the project directory containing just one line “PostSharp”. If you execute “paket install” in your command promt, paket adds PostSharp as reference to the project and modifies the csproj accordingly.

The next time you run a build, PostSharp comes up with this dialog:

postsharp

Since the VisualStudio PostSharp plugin detects a reference to PostSharp.dll, it expects a packages.config which it can’t find. If you don’t agree, the solution builds successfully but the code won’t be modified by PostSharp.

imageIf you agree, PostSharps adds a packages.config and replaces the existing PostSharp reference with the newest stable one (which probably is not the version you have specified in Paket!).

I posted this on Twitter. The Paket maintainers can’t handle this and PostSharp won’t change this behaviour.

image

image

image

So by now, I don’t see any solution except that Paket users can ask PostSharp to change this behaviour.

//Edit: Have a look at the comments. The unsolved problem is that you have to execute the „install.ps1“. Paket doesn’t do that but NuGet will also remove this feature in a future release.

PostSharp Fast Track Webinar – Feedback

German:

Das Webinar ging knapp 35 Minuten, obwohl in der Einladung 1 Stunde stand. Aber persönlich bevorzuge ich es, wenn Termine nicht länger gehen, sondern höchstens früher aufhören (Stichwort timeboxed). Der Sprecher hatte eine angenehme Sprechweise und war gut verständlich.

Leider waren die ersten 10 Minuten reine Basics, z.B. wurde der Unterschied zw. PostSharp und Containern erläutert. Das pfeifen die Vögel ja inzwischen von allen Dächern, von daher: Lass weg, hau mehr technische Infos rein. Interessant sind die neuen Möglichkeiten mit den ready-to-use Aspekten, die die Ultimate Lizenz mitbringt. Primär ist interessant wie gut das seit Version 3 integriert ist. Typischerweise kamen die Einstiegsbeispiele der vergangenen Jahre wieder zur Geltung: INotifiyPropertyChanged, Logging, Transaction. Auch das zähle ich noch zu den Basics.

Dann ging es weiter mit Möglichkeiten im Kontext von Threading-Szenarien. Die meisten Schwierigkeiten werden out-of-the-box abgedeckt. Richtig interessant wurde es für mich persönlich dann mit den neuen Architectual Constraints, die zumindest in dem Beispiel einen starken Eindruck hinterlassen haben. CQRS enforced by PostSharp – geil! Die Multicast-Option für projektweite Einstellungen waren mir zwar bekannt, allerdings hatte ich mich dazu noch nicht eingelesen, wie ich zu meiner Schande gestehen muss. Von daher war ich froh, dass dies ebenfalls gezeigt wurde.

Generell hat Adam in den 35 Minuten wirklich sehr viel gezeigt. Für mich wäre es noch spannender gewesen, wenn er sich stark auf die Neuerungen von PostSharp 3 und v.a. 3.1 konzentriert hätte. Sprich: Ein technischer Deep Dive. So wie die Folien aufgebaut waren, wie er das Webinar führte und basierend auf seiner Biographie, denke ich, dass ihm das problemlos möglich wäre. Deshalb an dieser Stelle die Bitte: Deep Dive für Fortgeschrittene!

 

English:

The webinar only took about 35 minutes, although it said it would last an entire hour in the invitation. But it’s an personal preference of mine, if meetings don’t last too long, but end prematurely (keyword: timeboxed). The speaker had an excellent manner of speaking and was very comprehensible.

Unfortunately the first 10 minutes covered only the basics, for example the difference between Postsharp and Containers was explained. That’s considered common knowledge nowadays, so: Leave that out, focus on technical info! The new possibilities of the ready-to-use aspects, that the Ultimate Licencse brings along, are more interesting. The good integration in version 3 is of particular interest. The usual beginner examples of last year made another occurance: INotifiyPropertyChanged, Logging, Transaction. I consider those common knowledge as well.

Next, he showed some threading practices. There are some handy features which cover most of the common difficulties in multithreading. After that, he started with my personal favorite: Architectual Constraints. Very impressive. CQRS enforced by PostSharp – awesome. I knew about Multicasting aspects, but to my shame I have to admit that I haven’t already concerned myself with that. So thanks for showing it.

Summing up: Adam did a great job, showing lots of things in just about 35 minutes. Personally, I would have been more excited about just the features of PostSharp 3 and especially 3.1 (like these). Listening to him, seeing his demo and reading his biography excerpt , I’m convinced he could come up with a technical deep dive without any difficulties. So my request to PostSharp: Deep dive for “advanced learners”.

PostSharp & SmartInspect

Dieser Blogeintrag liefert ein paar weiterführende Informationen zu meinem zugehörigen Webcast. Darin thematisiere ich wie sich die Geschäftslogik frei von Infrastructure Code halten lässt. Eine Möglichkeit dazu bietet z.B. aspektorientierte Programmierung. Im .NET Umfeld ist PostSharp sehr gut geeignet. In dem Webcast zeige ich wie wir durch den Einsatz in Verbindung mit einem starken Logging Framework wie SmartInspect Concerns wie Logging, Exception Handling, Performance Measuring und Tracing umsetzen.

Wer gerne den Code hätte, kann mich über die üblichen Kanäle wie Twitter und Xing anschreiben. Die SmartInspect Konfiguration sieht wie folgt aus:

AppName = UAR
Connections = tcp(caption="Hello World")
DefaultLevel = Message
Enabled = True
Level = Message
SessionDefaults.Level = Message
SessionDefaults.Active = True
SessionDefaults.Color = 0x00FF40

Webcast:

PostSharp und SmartInspect zur Reduzierung der Code Vermischung

Aktualisierung vom 11.11.12 um 13.50:

Weil die Frage nach Performance aufkam, noch kurz zwei Infos: Über SkipPostSharp=false in den Build Skripten kann PostSharp deaktiviert werden. Außerdem hat Daniel Marbach eine Analyse mit 125000 Codezeilen gemacht und der CompileTime Ovewrhead lag bei lediglich einer Sekunde.

%d Bloggern gefällt das: