在构建 C# 项目时让 Visual Studio 复制 x64 DLL 或 x86 DLL [英] Have visual studio copy x64 DLL or x86 DLL when building a C# project

查看:33
本文介绍了在构建 C# 项目时让 Visual Studio 复制 x64 DLL 或 x86 DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在构建一个 C# 应用程序,它使用 Sqlite.NET 的外部 DLL.这是一个 .NET dll,但它在其中嵌入了一个 C dll,因此它具有 x86 和 x64 风格.

We're building a C# app that uses an external DLL for Sqlite.NET. This is a .NET dll but it embeds a C dll inside it and so it comes in x86 and x64 flavours.

我们在项目中添加了对 x86 版本的引用,因此当我们在 x86 上构建和运行时,它很好.Visual Studio 将 dll 复制到 bin 文件夹并运行.

We add a reference to the x86 version in the project so when we build and run on x86 it's fine. Visual studio copies the dll to the bin folder and runs.

在 x64 上,它当然仍然复制 x86 版本,然后在运行时无法加载它.我们通过暂时将我们的项目设置为仅 x86 来解决这个问题,但理想情况下,我们希望告诉 Visual Studio 根据它是哪种机器来复制正确的版本.

On x64 it still copies the x86 version of course and then when it runs it fails to load it. We get round this by temporarily setting our project to be x86 only, but ideally we'd like to tell visual studio to copy the correct version depending on which flavour of machine it is.

有什么想法吗?

推荐答案

这可以在 MSBuild 中完成(即您需要卸载项目并编辑 .csproj 文件).

This can be done in MSBuild (i.e. you need to unload the project and edit the .csproj file).

本质上,在以平台为条件的属性组中添加一个属性以标识适当程序集的路径,然后在引用项组中使用该属性.

Essentially add a property in the property groups that are conditional on the platform to identifier the path of the appropriate assembly, and then use that property in the references item group.

答案在这里:条件参考在 .NET 项目中,可以摆脱警告吗?

这篇关于在构建 C# 项目时让 Visual Studio 复制 x64 DLL 或 x86 DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆