无法在C#控制台应用程序中使用外部引用 [英] Cannot use external references with C# Console Application

查看:407
本文介绍了无法在C#控制台应用程序中使用外部引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下所有建议,但仍然不满意.

我现在正在尝试一个控制台应用程序,让我确切地解释我在做什么.

  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服务).

肯定有某些我想念的东西,否则我现在可以解决这个问题.

解决方案

将项目Target更改为非Client Profile目标.右键单击项目",然后选择属性",您应该会看到Framework版本的列表.使用VS2010时,默认情况下创建的Console项目以.NET Framework 4.0 Client Profile为目标,将其更改为.NET Framework 4.0.

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.

解决方案

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.

这篇关于无法在C#控制台应用程序中使用外部引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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