The configuration method of Visual Studio that refers to 64 bit and 32 bit DLL dynamic library files according to the system distinction

  • 2020-10-23 20:16:06
  • OfStack

The original 32-bit system of Win7 was used for the development of C# project, and later the system was reinstalled and replaced with the 64-bit system of win7

Debugging the original project, where the 32-bit dll of "SQLite" was referenced, caused the program to not run in 64-bit (but compile ok)

The problem was later solved by modifying the project file (.csproj) to set conditions for references

Open the project file (info.csproj) for a project that references SQLite (for example, called info) and find the statement that refers to SQLite, similar to the following code


<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>

The name, path, and other information of the referenced library are specified here. The configuration above is modified as follows


<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>

Only one Condition restriction is added, indicating that dll is referred to in this path only if the platform type is AnyCPU

Copy the above configuration and modify as follows to set the dll path referenced at build time for the x64 platform

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

Finally, how do you set up different generation platforms in VS

In the Solution Platform toolbar (1 general displays Any CPU), select Configuration Manager in the drop-down box and add the desired platform type (1 general x64, x86, Itanium, do not change the default name)

Then change the platform type (to X64) in the project Context at the bottom of the window in the corresponding project (info only here, leaving AnyCPU unchanged for the rest)

Then, configure here. Maybe in the project file, some Settings of the newly added platform type 1 are not complete (" OutputPath is not set "when I encountered compilation). At this time, enter the project properties interface of vs and slightly modify these Settings (change to other, save, and change back)

ok, at this point, you should be able to refer to the corresponding dll depending on the type of platform,

According to the information found on the Internet, this method is not very good for the production of msi's installation program. I am not clear about it. If it involves students in this field, please check it carefully.

However, One possible solution I offer here is not to build the entire project into an installer, but to build a basic installer and then upgrade to keep it up to date.

If you are in a non-networked environment, you can also unpack the compiled output separately to the installation directory to avoid making the entire solution into an installation package.


Related articles: