wpf 不明白为什么我们会收到错误 CS0234

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35419905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:40:26  来源:igfitidea点击:

Don't understand why we're getting error CS0234

c#wpf

提问by Rod

We're working on a WPF project using Visual Studio 2015. We've got a folder in the project named Assets. It shows up fine in VS 2015. The files in it show up fine in the Solution Explorer. But when we build it, VS 2015 complains with the following error:

我们正在使用 Visual Studio 2015 处理 WPF 项目。我们在项目中有一个名为 Assets 的文件夹。它在 VS 2015 中显示良好。其中的文件在解决方案资源管理器中显示良好。但是当我们构建它时,VS 2015 抱怨以下错误:

"Error CS0234 The type or namespace name 'Assets' does not exist in the namespace 'CoreFramework' (are you missing an assembly reference?)"

“错误 CS0234 命名空间‘CoreFramework’中不存在类型或命名空间名称‘Assets’(您是否缺少程序集引用?)”

(CoreFramework is the name of our solution and the project that Assets is in.)

(CoreFramework 是我们的解决方案和 Assets 所在项目的名称。)

I don't get how the folder is there in CoreFramework, but when building it, VS 2015 just doesn't see it. I've tried cleaning both the project and the solution in VS 2015, but it doesn't help at all. The same errors keep popping up. And they popup in our nightly builds as well.

我不知道 CoreFramework 中的文件夹是如何存在的,但是在构建它时,VS 2015 只是看不到它。我已经尝试在 VS 2015 中清理项目和解决方案,但它根本没有帮助。同样的错误不断出现。它们也会出现在我们的夜间构建中。

So what is causing VS 2015 to simultaneously see a folder within a project and not see that same folder in the project?

那么是什么导致 VS 2015 同时看到项目中的一个文件夹,而在项目中看不到同一个文件夹呢?

采纳答案by Rod

In this case what I had to do was to delete everything in the obj folder beneath our project main folder. The solution's name is CoreFramework and the main project's name is also CoreFramework. So what I did was go to \CoreFramework\CoreFramework\obj and deleted everything there. Since at this point we're only dealing with a debug version, the only thing there was the Debug folder and all temporary files and folders under that. Once I did that, then rebuilding the solution re-created all of the temporary files and folders, without the problem I was having with the Assets folder. It built fine.

在这种情况下,我必须做的是删除项目主文件夹下 obj 文件夹中的所有内容。解决方案的名称是 CoreFramework,主项目的名称也是 CoreFramework。所以我所做的是去 \CoreFramework\CoreFramework\obj 并删除那里的所有内容。由于此时我们只处理调试版本,因此唯一存在的就是 Debug 文件夹以及其下的所有临时文件和文件夹。一旦我这样做了,然后重建解决方案会重新创建所有临时文件和文件夹,而不会出现我在 Assets 文件夹中遇到的问题。它建造得很好。

YMMV

青年会

回答by leguminator

I had the same issue after I manually copied the referenced DLL file. I solved it by displaying the reference properties in the Solution explorer then changing the Specific version setting from True to False and finally changing it back to True. I rebuild and... it works just fine. Do not ask me why...

手动复制引用的 DLL 文件后,我遇到了同样的问题。我通过在解决方案资源管理器中显示参考属性,然后将特定版本设置从 True 更改为 False 并最终将其更改回 True 来解决它。我重建并......它工作得很好。别问我为什么...

Note : I had to do the same for each project which had the CS0234 error message

注意:我必须为每个有 CS0234 错误消息的项目做同样的事情

PS : in my case Visual studio version is 16.1.6

PS:就我而言,Visual Studio 版本是 16.1.6