In the Visual Studio project, a 32-or 64-bit DLL is automatically referenced based on the system platform.

Source: Internet
Author: User

I recently used noesis. Javascript. dll, but this DLL is available in x86 and x64 versions. My own computer is 64-bit, but others' computers are 32-bit. So there is a problem when using it in other people.

How to reference two versions of DLL in. Search for documents online. The code I modified is as follows: (you can check the information later)

    <Reference Condition=" '$(Platform)' == 'AnyCPU' " Include="Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c7f89f85, processorArchitecture=AMD64">      <SpecificVersion>False</SpecificVersion>      <HintPath>lib\x86\Noesis.Javascript.dll</HintPath>    </Reference>    <Reference Condition=" '$(Platform)' == 'x86' " Include="Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c7f89f85, processorArchitecture=AMD64">      <SpecificVersion>False</SpecificVersion>      <HintPath>lib\x86\Noesis.Javascript.dll</HintPath>    </Reference>    <Reference Condition=" '$(Platform)' == 'x64' " Include="Noesis.Javascript, Version=0.0.0.0, Culture=neutral, PublicKeyToken=ae36d046c7f89f85, processorArchitecture=AMD64">      <SpecificVersion>False</SpecificVersion>      <HintPath>lib\x64\Noesis.Javascript.dll</HintPath>    </Reference>



Recently, the system was changed from win2008 (32-bit) to win2008r2, and an exception occurred when using the program originally developed in a 32-bit system in a 64-bit system. After debugging, it turns out that the 32-bit DLL of "system. Data. SQLite" is referenced in it, so that the program cannot run in 64-Bit mode (but can be compiled through) powered by 25175.net

Solution:

1. download the latest x64 DLL from the http://sourceforge.net/projects/sqlite-dotnet2/files/. After compilation, it can run normally on a 64-bit system, but it cannot run on a 32-bit system at the same time.


2. Find Solutions to automatically adapt projects to different platforms.

Solution:



Modify the csproj (C # project file extension) file configuration to adapt to the corresponding platform, where $ {platform} represents the corresponding Platform

Method 1. Use $ {platform} In hintpath as the variable replacement path

Assume that your dll has two platforms to build and they are located in the following locations:

C:\whatever\x86\whatever.dll  
C:\whatever\x64\whatever.dll 

You only need to edit the. csproj file for this Protocol:

<HintPath>C:\whatever\x86\whatever.dll</HintPath>  

Is:

<HintPath>C:\whatever\${Platform}\whatever.dll</HintPath>  

Then, you should be able to build your project for these two platforms, and msbuild will seek other platforms of choice, for the correct directory.



Method 2: add the condition to the reference node.

A. Add the condition to the 32-bit reference node.

<Reference Condition=" '$(Platform)' == 'AnyCPU' "……

B. Copy the 32-bit platform reference node and change it to the 64-bit platform. Replace the dll path in the hintpath node with the corresponding 64-bit version.

<Reference Condition=" '$(Platform)' == 'x64' ……

Method 3: The itemgroup node adds the condition. Its implementation is the same as method 2, but the nodes used are different. This is skipped.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.