无法将外部引用与 C# 控制台应用程序一起使用
我已经尝试了下面的所有建议,但仍然没有喜悦。
我现在正在尝试一个控制台应用程序,让我准确解释一下我在做什么。
- 我在 VS 2010 中创建了一个新的控制台项目
- 我在控制台应用程序中添加了一些不是我的引用(dll),例如 Castle.Winsor 和 N2 CMS dll
- 我可以添加 using 语句,表明我正在使用名称空间引用了DLL
- 我开始编写代码。
- 一旦我编译所有使用引用的 DLL 的代码,就会立即抱怨“找不到类型或命名空间名称(您是否缺少 using 指令或程序集引用?)”,
我尝试将 DLL 设置为复制始终到本地,我已将 DLL 复制到同一目录中,我尝试按项目添加引用并添加对 DLL 本身的引用
我在 Web 应用程序项目或 ASP.net 项目中不会遇到此问题,它们总是可以工作好吧,只有编译成 EXE 的东西,比如控制台应用程序或 Windows 服务。
一定是我遗漏了一些东西,否则我现在就可以正常工作了。
I have tried all the suggestions below but still no joy.
I'm now trying a console application, and let me explain exactly what I'm doing.
- I create a new console project in VS 2010
- I add a number of references (dll's) some that aren't mine such as Castle.Winsor and N2 CMS dlls
- in the console app I can add using statements indicating I am using name spaces within the referenced DLLs
- I start writing code.
- As soon as I compile all the code that uses the referenced DLLs immediately complains with "The type or namespace name '' could not be found (are you missing a using directive or an assembly reference?)"
I have tried setting the dlls to copy to local always, I have copied the DLL into the same directory, I have tried added reference by project and adding a reference to the DLL's themselves
I don't get this problem with a web application project or a ASP.net project they always work fine, only something that is compiled to an EXE like a console app or windows service.
there must be something I'm missing or I would have got this working by now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
将项目目标更改为非客户配置文件目标。右键单击项目并选择属性,您应该会看到框架版本列表。由于您使用的是 VS2010,默认情况下创建的控制台项目的目标是 .NET Framework 4.0 Client Profile,请将其更改为 .NET Framework 4.0。
Change the project Target to a non Client Profile target. Right click the Project and select Properties, you should see a list of Framework versions. As you are using VS2010, the Console project you've created by default targets .NET Framework 4.0 Client Profile, change that to .NET Framework 4.0.
检查引用的程序集的
Copy Local
是否设置为true
。Check if
Copy Local
is set totrue
for the referenced assembly.首先,关于你的问题,很难确切地知道你做错了什么,但从你在程序集名称(可能在命名空间和类型名称)中使用下划线的事实来看,这表明你相当.NET 世界的新手。
这表明您通过浏览已编译的程序集来添加对解决方案中其他项目的引用,而不是通过添加项目引用。添加引用时,您必须选择“项目”选项卡,而不是浏览程序集。
即使您不认为这就是问题所在,也可以删除所有引用并重新添加项目引用以确保万无一失。假设、评估等。
完成这些后,我强烈建议从类型、命名空间和程序集中删除所有下划线。您可能还想阅读框架设计指南。
First, as to your question, its hard to know exactly what you're doing wrong, but from the fact that you're using an underscore in an assembly name (and probably in namespaces and type names), it suggests you're rather new to the .NET world.
This suggests that you're adding references to other projects in your solution by browsing to the compiled assembly, rather than by adding a Project Reference. When adding a reference, you must select the Project tab rather than browsing for the assembly.
Even if you don't believe this is the issue, remove all references and re-add project references to make absolutely sure. Assumption, asses etc.
Once you've done that, I'd strongly suggest remove all the underscores from your types, namespaces and assemblies. You might want to go read the framework design guidelines, too.
在记事本中打开您的.Proj(Windows服务项目文件)文件,然后检查您的程序集位置(data_object)是否与您指向的位置相同。
当您在记事本中打开 .Proj 文件时,您可以检查
项目引用,
如果您提供 dll 或 exe 引用,那么
我建议您提供确切的位置,包括驱动器名称,如上面的示例。
您可以尝试其他选择,
Open your .Proj(Windows service project file) file in notepad and check whether your assembly location(data_object) is the same which you are pointing.
When you open .Proj file in notepad you can check for,
Project reference,
And if you giving dll or exe refrence then
I suggest you to give exact location including drive name like above example.
Other option you may try,
在 VS 2019 中,我有两个项目,一个是 C++,另一个是 C# 控制台,位于一个解决方案文件中。当尝试通过“添加引用”添加 dll 引用时,我无法在“引用管理器”窗口中看到用于选择 dll 文件的浏览按钮。
但是,当我在解决方案中仅创建 C# 控制台应用程序时,我可以添加 dll 引用。
In VS 2019, I had two projects, one C++ and other one C# Console in one solution file. When tried to add a dll reference through "Add reference", I was not able to see Browse button in "Reference Manager" window, to select dll file.
But when I created only C# Console app inside solution then I could add dll reference.