从C#应用程序添加引用到没有/ clr编译的DLL? [英] Add a Reference from a C# App to a DLL compiled without /clr?

查看:404
本文介绍了从C#应用程序添加引用到没有/ clr编译的DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Visual Studio 2008来构建一个带有两个项目的解决方案:一个C#控制台应用程序和一个C ++ DLL。我想让应用程序使用P / Invoke从dll调用函数。因此,我试图添加的dll作为参考的C#应用​​程序。但是当我尝试添加引用命令,Visual Studio不会让我这样做,除非我设置/ clr属性在dll(在配置属性:一般)。现在,我认为P / Invoke可以处理普通的win32 dll。事实上,如果我构建我的DLL没有/ clr,只是手动复制到bin / Debug,那么应用程序运行良好。那么为什么是/ clr需要添加dll作为参考?如果VS不会让我添加它,是否有一些(干净的)解决方法,以便我的应用程序找到dll?

I'm using Visual Studio 2008 to build a Solution with two Projects: a C# Console App and a C++ DLL. I want the app to call a function from the dll using P/Invoke. Therefore I'm trying to add the dll as a Reference to the C# app. But when I try the Add Reference command, Visual Studio won't let me do it unless I set the /clr property on the dll (under Configuration Properties:General). Now, I thought that P/Invoke could handle plain-old win32 dlls. Indeed, if I build my dll without /clr and just copy it by hand to bin/Debug, then the app runs fine. So why is /clr required to add the dll as a reference? And if VS won't let me add it, is there some (clean) workaround so that my app finds the dll?

我看到有人有类似的问题(虽然使用第三方dll):
http://stackoverflow.com/questions/1377019/unable-to-add-a-dll-reference-to-vs-2008 他得到的答案是构建一个包装器。但这不是真的有必要,因为应用程序可以使用dll只是罚款;它只是添加引用步骤不工作。此外,包装程序代码是否需要引用dll,提出与以前相同的问题?

I see that someone had a similar issue here (though with a 3rd-party dll): http://stackoverflow.com/questions/1377019/unable-to-add-a-dll-reference-to-vs-2008 The answer he got was to build a wrapper. But this isn't really necessary, since the app can use the dll just fine; it's just the Add Reference step that doesn't work. And besides, won't the wrapper code need a reference to the dll, raising the same problem as before? I'd really like an answer that doesn't involve writing a wrapper at all.

推荐答案

为什么不只是添加一个post-构建步骤将您的非托管DLL复制到您的项目目录?你不需要一个引用来引用一个非托管DLL,听起来像你遇到的唯一的问题是由于该文件不会自动复制到搜索路径。

Why not just add a post-build step to copy your unmanaged DLL to your project directory? You don't need a "reference" to be able to refer to an unmanaged DLL, and it sounds like the only problem you're experiencing is due to the file not being automatically copied into the search path.

这篇关于从C#应用程序添加引用到没有/ clr编译的DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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