xiao123

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

这里主要讨论的是Refrence文件位置依赖于编译的Platform(Any CPU,x86,x64...关于这部分可以参考http://www.cnblogs.com/taoxu0903/archive/2010/11/23/1885043.html

主要实现方法有两种:

1,直接修改项目文件.csproj:

  用notepad打开项目的.csproj文件,找到对应的Refrece节点,我这里引用的是Sqlite数据库的Dll,(据说是用C语言写的,所以也就有了x64和x86之分。)如下:

<Reference Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\libs\SQLite\System.Data.SQLite.dll</HintPath>
</Reference>

其中HintPath节点中对应的就是该dll对应的文件位置。

  修改上面的节点,添加Condition条件,如下所示:

<Reference Condition=" '$(Platform)' == 'AnyCPU' " Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\libs\SQLite\System.Data.SQLite.dll</HintPath>
</Reference>

则编译Platform设置成Any CPU时就会调用对应节点HintPath的路径的Dll。

  同样可以添加如下Refrence:

<Reference Condition=" '$(Platform)' == 'x86' " Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\libs\SQLite\System.Data.SQLite.x86.dll</HintPath>
</Reference>

<Reference Condition=" '$(Platform)' == 'x64' " Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\libs\SQLite\System.Data.SQLite.x64.dll</HintPath>
</Reference>

以上方法参考http://blog.sina.com.cn/s/blog_6d541f310100mfuq.html

2.在GAC里面分别添加32位和64位的DLL

  GAC在本机的路径为C:\Windows\assembly,在Microsoft SDKs中提供了一个gacutil.exe(路径为”C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\gacutil.exe“)工具,利用该工具可以把对应的dll添加到GAC中。

gacutil.exe -i C:\MPlusPlatform\bin\release\System.Data.SQLite.dll

  调用以上指令就会填加对应的DLL到GAC中,可以同时把x64和x86对应的dll都添加到GAC中,名字相同没有关系。yoganotepad打开项目的.csproj,添加Reference节点,如下所示:

<Reference Include="System.Data.SQLite">
      <SpecificVersion>False</SpecificVersion>
    </Reference>

  VS会直接从GAC中找到对应Platform的dll。

注:在网上看到好像可以直接拖动DLL到“C:\Windows\assembly”下就会添加进来。

 

posted on 2012-06-19 15:45  xiao123  阅读(375)  评论(0编辑  收藏  举报