在 C# Visual Studio 中出现错误,并且在线上似乎没有对此问题的任何明确的答案。
当我想添加 mscorlib 时,我收到此错误消息
无法添加对“mscorlib”的引用。该组件由项目系统自动引用,不能直接引用。
但是 .EnuerateFiles() 需要那个库。
为什么要添加特定参考时会显示此消息??
在 C# Visual Studio 中出现错误,并且在线上似乎没有对此问题的任何明确的答案。
当我想添加 mscorlib 时,我收到此错误消息
无法添加对“mscorlib”的引用。该组件由项目系统自动引用,不能直接引用。
但是 .EnuerateFiles() 需要那个库。
为什么要添加特定参考时会显示此消息??
MSDN is good place to solve such misteries -DirectoryInfo.EnumerateFiles clearly show that it is supported by 4.0 and 4.5 versions of .Net.
You are trying to link against 2.0 (or maybe something like 3.0/3.5) and do not have such function. Erro clearly says that you can't add the assembly to the project since it is always referenced automatically for correct version of runtime.
To be able to use new EnumerateFile you need to build agains 4.0+ , or write code without that function.
EnumerateFiles require .NET 4 or later. I think you are building your solution targetting .NET Framework 3.5 or earlier.