我创建了一个名为Foo的解决方案。添加了一个名为Foo.Common的类库,添加了一个控制台应用程序来调用名为ConsoleApp的库代码。
Foo.Common I引用了 ConsoleApp中的并输入:
using Foo.Common;
public class Program
{
CommonClass c = new CommonClass();
static void Main(string[] args)
{
}
}把这个拿回来:
Error 1 The type or namespace name '**Foo**' could not be found (are you missing a using directive or an assembly reference?) Z:\Foo\Solution1\ConsoleApplication1\Program.cs 3 11 ConsoleApplication1
我为什么要得到这个?
怎么回事?
发布于 2011-07-15 02:50:17
请确保

文件包含声明and
CommonClass的名称空间的using指令,被声明为public.所以你的文件应该是这样的:
CommonClass.cs in Foo.Common项目:
namespace Foo.Common
{
public class CommonClass
{
public CommonClass()
{
}
}
}Program.cs in ConsoleApp项目:
using Foo.Common;
namespace ConsoleApp
{
public class Program
{
public static void Main()
{
CommonClass x = new CommonClass();
}
}
}发布于 2011-08-26 21:17:27
确保在项目设置下,目标框架设置为.NET Framework4,而不是.NET Framework4客户端配置文件。当它被设置为客户端配置文件时,我得到了同样的行为,并且当我将它设置为常规的.NET框架4时,它就被修复了。
发布于 2011-07-15 02:32:14
右键单击新控制台应用程序解决方案/项目,添加引用并添加包含Foo命名空间的项目
https://stackoverflow.com/questions/6702099
复制相似问题