无法将外部引用与 C# 控制台应用程序一起使用

发布于 2024-10-10 01:40:22 字数 511 浏览 1 评论 0原文

我已经尝试了下面的所有建议,但仍然没有喜悦。

我现在正在尝试一个控制台应用程序,让我准确解释一下我在做什么。

  1. 我在 VS 2010 中创建了一个新的控制台项目
  2. 我在控制台应用程序中添加了一些不是我的引用(dll),例如 Castle.Winsor 和 N2 CMS dll
  3. 我可以添加 using 语句,表明我正在使用名称空间引用了DLL
  4. 我开始编写代码。
  5. 一旦我编译所有使用引用的 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.

  1. I create a new console project in VS 2010
  2. I add a number of references (dll's) some that aren't mine such as Castle.Winsor and N2 CMS dlls
  3. in the console app I can add using statements indicating I am using name spaces within the referenced DLLs
  4. I start writing code.
  5. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

送君千里 2024-10-17 01:40:22

将项目目标更改为非客户配置文件目标。右键单击项目并选择属性,您应该会看到框架版本列表。由于您使用的是 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.

始于初秋 2024-10-17 01:40:22

检查引用的程序集的Copy Local 是否设置为true

Check if Copy Local is set to true for the referenced assembly.

夜未央樱花落 2024-10-17 01:40:22

首先,关于你的问题,很难确切地知道你做错了什么,但从你在程序集名称(可能在命名空间和类型名称)中使用下划线的事实来看,这表明你相当.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.

鱼忆七猫命九 2024-10-17 01:40:22

在记事本中打开您的.Proj(Windows服务项目文件)文件,然后检查您的程序集位置(data_object)是否与您指向的位置相同。

当您在记事本中打开 .Proj 文件时,您可以检查

项目引用,

        <ProjectReference Include="C:\StackOverflow\StackOverflow.csproj">

如果您提供 dll 或 exe 引用,那么

 <Reference Include="StackOverflow, Version=1.0.0.0, Culture=neutral,       processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion>
  <ExecutableExtension>.exe</ExecutableExtension>
  <HintPath>C:\StackOverflow\bin\Debug\StackOverflow.exe</HintPath>
</Reference>

我建议您提供确切的位置,包括驱动器名称,如上面的示例。

您可以尝试其他选择,

 1. Clean and rebuild
 2. Add Project reference if you already tried dll reference
 3. Check whether the folder (referred assembly location) is Read Only then remove it. 

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,

        <ProjectReference Include="C:\StackOverflow\StackOverflow.csproj">

And if you giving dll or exe refrence then

 <Reference Include="StackOverflow, Version=1.0.0.0, Culture=neutral,       processorArchitecture=x86">
  <SpecificVersion>False</SpecificVersion>
  <ExecutableExtension>.exe</ExecutableExtension>
  <HintPath>C:\StackOverflow\bin\Debug\StackOverflow.exe</HintPath>
</Reference>

I suggest you to give exact location including drive name like above example.

Other option you may try,

 1. Clean and rebuild
 2. Add Project reference if you already tried dll reference
 3. Check whether the folder (referred assembly location) is Read Only then remove it. 
隔岸观火 2024-10-17 01:40:22

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文