PostSharp Aop(安装)

项目中 Business层,大多数代码都是public static fun(string xx) 这样的代码,没有接口。AOP 对象都是依赖于接口的,对于这种无接口的类有没有办法AOP。
答案有肯定的。可以用PostSharp。

AOP 依赖接口的我称之为动态AOP,编译时(MSIL)称之为静态AOP。

PostSharp,mono.cecil 都是商业版的,都可以静态AOP。

castle,微软企业库,spring.net 都是动态AOP。

引用星爷的一句话:谁说没有枪头就捅不死人(谁说非要接口才能AOP)。


下载
https://www.postsharp.net/purchase
image 


image     image



所有的Project 必须Add postSharp to Project只引用DLL是无法使用AOP的

image E7)ENZ90UZNVVOXD7K1Y2(Q


添加完毕后.csproj文件用文本打开,会有Msbuild信息。


<Import Project="$(MSBuildToolsPath)Microsoft.CSharp.targets" />
<Import Project="......packagesPostSharp.4.0.41 oolsPostSharp.targets" Condition="Exists('......packagesPostSharp.4.0.41 oolsPostSharp.targets')" />
<Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
  <Error Condition="!Exists('......packagesPostSharp.4.0.41 oolsPostSharp.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." />
  <Error Condition="Exists('......packagesPostSharp.4.0.41 oolsPostSharp.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." />
</Target>


postsharp 2.0之前没有Msbuild,2.0之后会存在Msbuild信息。

原文地址:https://www.cnblogs.com/kfsmqoo/p/4286109.html