且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法在C#控制台应用程序中使用外部引用

更新时间:2022-10-18 14:32:42

将项目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.