场景
基于visual studio
项目有编译多平台的需求,即需要支持编译成x86与x64。
- 项目在
solution里直接引用其他的项目时,可以不用考虑这个问题,因为在Build Dependencies时会根据依赖顺序流式编译,并保持相同的编译参数。 - 项目在引用第三方dll时,一般都是通过
Add reference+broswer选择对应的dll,而这样就是明确指定了编译类型。
方案
- 在添加了dll后,修改项目配置文件。
xxx.csproj。 - 在·
<ItemGroup> / <Reference>目录下,找到引用的dll。 - 使用
$(PlatformName)(x86/x64,由项目编译参数决定)$(ConfigurationName)(debug/releas,由项目编译参数决定)
<ItemGroup>
<Reference Include="xxx">
<HintPath>..\Output\api\x86\debug\xxx.dll</HintPath>
</Reference>
<Reference Include="yyy">
<HintPath>..\Output\api\x86\yyy.dll</HintPath>
</Reference>
<ItemGroup>
// 由上改至下
<ItemGroup>
<Reference Include="xxx">
<HintPath>..\Output\api\$(PlatformName)\$(ConfigurationName)\xxx.dll</HintPath>
</Reference>
<Reference Include="yyy">
<HintPath>..\Output\api\$(PlatformName)\yyy.dll</HintPath>
</Reference>
<ItemGroup>
以上就可以实现根据编译参数动态引用第三方dll。

本文介绍了如何在Visual Studio项目中实现编译多平台时动态引用x86和x64的DLL。通过修改项目配置文件csproj,在Reference中使用$(PlatformName)和$(ConfigurationName)变量,根据编译参数动态调整DLL路径,确保编译过程中正确引用相应平台的库。
3138

被折叠的 条评论
为什么被折叠?



