我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
我得到一个:
找不到类型或名称空间名称
错误的c# WPF应用程序在VS2010。这部分代码编译得很好,但突然就出现了这个错误。我已经尝试删除项目引用和using语句,关闭VS2010并重新启动,但我仍然有这个问题。
有什么想法,为什么这可能会发生,似乎我在做正确的事情re Reference & using语句?
我还注意到在VS2010,智能感知的名称空间是工作的好,所以它似乎VS2010有项目引用,是看到名称空间在一方面,但在编译期间没有看到它?
当前回答
在我的情况下,我卸载项目,然后:
Opened myProject.csproj and update the ToolsVersion="4.0" to ToolsVersion="12.0"(I'm using vs 2017)(using Paulus's answer https://stackoverflow.com/a/64552201/1594487). Deleted following lines from the myProject.csproj: <Import Project="..\packages\EntityFramework.6.4.0\build\EntityFramework.props" Condition="Exists('..\packages\EntityFramework.6.4.0\build\EntityFramework.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
问题解决了。
其他回答
要解决这个问题,还可以删除并重新创建*.sln。关联解决方案的DotSettings文件。
我知道这是老问题了,但我也发现了同样的问题。我的项目确实构建了,然后我将Visual Studio更新到最新&项目不会构建,因为它无法从单独的程序集找到类型定义。另一个程序集构建OK,主项目正确地引用了它&自从它构建OK以来没有任何变化。
我清理了整个解决方案并重新构建了它,它失败了。我自己做了这个组件,它做得很好。这个工程没有建成。我多次清洁和建造,但它失败了。然后我叫了一个同事去看,当我在他的监视下建造时,一切都建好了。
我认为Visual Studio工具是问题所在,特别是我刚刚更新了它。
在面对上述错误时,我发现了一个非常简单的解决方案: 在控制台,我只是运行
dotnet build
之后,Visual Studio中的所有错误消息都消失了。
在我的例子中,我进入解决方案属性,并确保在两个项目的配置中选中了“Build”。我的主要项目没有检查。
I had a similar issue: The compiler was unable to detect a folder inside the same project, so a using directive linking to that folder generated an error. In my case, the problem originated from renaming the folder. Even though I updated the namespace of all the classes inside that folder, the project info somehow failed to update. I tried everything: deleting the .suo file and the bin and obj folders, cleaning the solution, reloading the project - nothing helped. I resolved the problem by deleting the folder and the classes inside, creating a new folder and creating new classes in that new folder (simply moving the classes inside the new folder didn't help).
PS:以我为例,我正在开发一个web应用程序,但这个问题可能发生在不同类型的项目中。