IT Giant

博客园 首页 新随笔 联系 订阅 管理
  4 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

公告

2011年12月23日 #

废话少说,不知道postSharp是什么的可以百度一下。

一、配置

1、下载到的源码打开解决方案时会报错,说是找不到Config.targets。解决办法:从Build文件夹下找到Config.targets.ori,把名字改为Config.targets

2、进入源码文件夹下的Build子文件夹,把PostSharp-32bit.reg的数据导入到注册表,不然会在编译时会提示强名称验证失败。如果你不想用原来的强名称密钥对,在更换的时候要记得修改这个注册表文件里的publickeytoken。

3、下载Nant,有个项目需要Nant

4、添加Nant.Core.dll的引用,编译

5、新建一个文件夹,把所有项目输出目录下的所有文件全部拷贝到该目录下,如C:\PostSharp1.5

6、添加环境变量POSTSHARP15,值为第4步你所建立的文件夹完整路径

7、查看C:\Program Files\MSBuild\v3.5目录,确认是否存在Custom.After.Microsoft.Common.targets文件,如果已经存在,打开该文件,在<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">的下面插入

<Import Project="C:\PostSharp1.5\PostSharp-1.5.targets" Condition=" '$(DontImportPostSharp)' == 'False' AND Exists('C:\PostSharp1.5\PostSharp-1.5.targets')" />;

如果不存在,自己新建一个,输入

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <Import Project="C:\PostSharp1.5\PostSharp-1.5.targets" Condition=" '$(DontImportPostSharp)' == 'False' AND Exists('C:\PostSharp1.5\PostSharp-1.5.targets')" /> </Project>

注意:C:\PostSharp1.5\PostSharp-1.5.targets这个值是根据第4步实际路径而定

8、在C:\Program Files\MSBuild文件夹下新建PostSharp子文件夹,在PostSharp文件夹下建立PostSharp-1.5.targets文件,输入

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  

  <PropertyGroup>    

    <PostSharpUseCommandLine Condition="'$(PostSharpUseCommandLine)'==''">True</PostSharpUseCommandLine>  

  </PropertyGroup>   <Import Project="C:\PostSharp1.5\PostSharp-1.5.targets"/>

</Project>

 

至此已经全部配置完成。

二、使用

1、新建一个项目

2、在此项目下新建一文件PostSharp.targets,文件内容为

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- This file detects the PostSharp installation directory according to
       deployment properties. It defines the PostSharpTargets property pointing
       to the target file that should actually be imported after importing the
       compiler.
       
       Every project should define the property DontImportPostSharp=True before
       importing C#/VB targets. -->

  <!-- Use a special target file when we are in source tree -->
  <Import Project="PostSharp-Samples-Src.targets" Condition="''!=''" />

  <!-- Other locations -->
  <PropertyGroup>
  
    <!-- This is where the targets file is supposed to be in the distribution tree-->
    <PostSharpDirectory Condition="'$(PostSharpDirectory)'=='' AND Exists('..\PostSharp-1.5.targets')">..</PostSharpDirectory>
    <!-- We can also try the MSBuild extension directory -->
    <PostSharpDirectory Condition="'$(PostSharpDirectory)'=='' AND Exists('$(MSBuildExtensionsPath)\PostSharp\PostSharp-1.5.targets')">$(MSBuildExtensionsPath)\PostSharp</PostSharpDirectory>
    <!-- Try the environment variable -->
    <PostSharpDirectory Condition="'$(PostSharpDirectory)'=='' AND Exists('$(POSTSHARP15)\PostSharp-1.5.targets')">$(POSTSHARP15)</PostSharpDirectory>
    <!-- Error. We did not find it. -->
    
  </PropertyGroup>

  <Import Project="$(PostSharpDirectory)\PostSharp-1.5.targets"  Condition="'$(PostSharpDirectory)'!=''" />

  <Target Name="BeforeBuild" Condition="'$(PostSharp15Imported)'!='True'">
    <Exec Command="cmd /c cd"/>
    <Error Text="Cannot find PostSharp." />
  </Target>
  
</Project>

  3、用记事本打开项目文件csproj,在适当位置加入以下内容

<PropertyGroup>
    <DontImportPostSharp>True</DontImportPostSharp>
  </PropertyGroup>

<Import Project="PostSharp.targets" />

 4、添加PostSharp.Core.dll、PostSharp.Laos.dll、PostSharp.Laos.Weaver.dll、PostSharp.Public.dll的引用

 PostSharp 1.5并不支持.NET 4.0,VS2010下使用会导致VS崩溃,现在正研究怎么让1.5也支持.NET 4.0。2.0版本支持.NET 4.0,有免费版本和商业版本。

编译好的PostSharp1.5

http://files.cnblogs.com/itgiant/PostSharp1.5.rar

 

测试代码下载

 http://files.cnblogs.com/itgiant/Backup.rar

 

posted @ 2011-12-23 17:56 IT Giant 阅读(1027) 评论(1) 编辑

2011年12月21日 #

 测试代码

需要用到强名称密钥对,得先生成密钥对。

首先打开 Microsoft Visual Studio 2010 x86 tools.

第一步,敲入sn -k c:\PostSharp.snk(这一步是生成私钥,名称和路径可以自己另外定义)

第二步,敲入sn -p c:\PostSharp.snk c:\PostSharpPublic.snk(这一步是根据私钥生成公钥)

 

第三步,敲入sn -tp c:\PostSharpPublic.snk(这一步是获取公钥字串,此时控制台会出现如下提示)

Microsoft(R) .NET Framework 强名称实用工具 版本 4.0.30319.1 版权所有(C) Microsoft Corporation。保留所有权利。

公钥为 002400000480000094000000060200000024000052534131000400000100010055fa6a030f9605 a175c0c7bd9e610c1d9c39b5f2a3834e0e1d10716e71be7a3de79380678236fefeef6c12273a9e 7a7fb102995b355b0bfd4f01f79948465a09409e1add83d4eff0881c08de62cc3cddb37d9712ee e260329013530c8c689dc918db0afdb62f73603d36c77199803fd773a6026c23b1ddc76607d956 4fd8e5e9

公钥标记为 bbe773d431a3500e

 

第四步,点选需要访问Internal类型的项目,右键,选属性,签名,”为程序集签名“打钩,浏览,选择刚才生成的PostSharp.snk

第五步,点选包含Internal类型的项目,右键,选属性,签名,”为程序集签名“打钩,浏览,选择刚才生成的PostSharp.snk

第六步,给Internal类型的程序集加上下面的代码,下面一连串的PublicKey就是从刚才第三步操作结果拷贝的。

[assembly:     InternalsVisibleTo(         "Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010055fa6a030f9605a175c0c7bd9e610c1d9c39b5f2a3834e0e1d10716e71be7a3de79380678236fefeef6c12273a9e7a7fb102995b355b0bfd4f01f79948465a09409e1add83d4eff0881c08de62cc3cddb37d9712eee260329013530c8c689dc918db0afdb62f73603d36c77199803fd773a6026c23b1ddc76607d9564fd8e5e9"         )]

至此大功告成。有点像C++里的友元。

posted @ 2011-12-21 13:37 IT Giant 阅读(945) 评论(3) 编辑

2011年10月3日 #

posted @ 2011-10-03 20:39 IT Giant 阅读(29) 评论(2) 编辑

2011年8月30日 #

摘要: 转自:http://www.codeproject.com/KB/IP/socketasynceventargs.aspx源码下载:http://files.cnblogs.com/itgiant/SocketAsyncServerAndClient.zipIntroductionMicrosoft created the SocketAsyncEventArgs class to help you write scalable, high performance socket server code. SocketAsyncEventArgs uses I/O Completion Port阅读全文
posted @ 2011-08-30 17:52 IT Giant 阅读(467) 评论(0) 编辑

仅列出标题