【问题标题】:Visual Studio 2010 doesn't see namespace, but it existsVisual Studio 2010 看不到命名空间,但它存在
【发布时间】:2014-02-17 05:07:22
【问题描述】:

我有解决方案,它有 5 个项目。其中之一:“Project.Core.Common”(.NET Framework 3.5)。我有他们的问题。当我尝试编译时,我得到错误:

错误 79 类型或命名空间名称“服务器”不存在于 命名空间“DllFile.Logging”(您是否缺少程序集 参考?)D:\Solution\Project.Core.Common

但是这个命名空间DllFile.Logging.Server 存在。我可以通过在对象浏览器中打开 DllFile.dll 来查看它。

在我的项目中添加了对DllFile.dll 的引用。

DllFile.dll 具有 .NET FW 2.0.50727 运行时版本。

我收到了 74 条关于此 DllFile.dll 的警告:

警告 4 主要参考“DllFile.Logging.Server, Version=6.3.1.0, 文化=中性,处理器架构=MSIL”无法解决 因为它间接依赖于 .NET Framework 程序集 “mscorlib,版本=4.0.0.0,文化=中性, PublicKeyToken=b77a5c561934e089" 具有更高版本 "4.0.0.0" 比当前目标中的版本“2.0.0.0” 框架。 Project.Core.Common

但是DllFile.dll 不使用任何对第四个框架的依赖。它是用 2.0 框架编写的。

还有重要的一点:这个项目在除我之外的任何计算机上编译都没有任何错误。我检查在以下环境中编译它:

VS 2010 (Windows XP SP3 x86)
VS 2010 (Windows 7 x86)
VS 2010 (Windows 7 x64)
VS 2013 (Windows 8.1 x64)

在每台计算机上,该项目都可以正常编译。但是在我的电脑上(VS 2010 Windows XP SP3 x86)我得到了这个错误和警告。

我想做什么:

  • 我完全卸载了 VS 2010 及其所有组件,然后重新安装。
  • 我删除了以下文件夹:

C:\Documents and Settings\User\Local Settings\Application 数据\程序集

C:\Documents and Settings\User\Local Settings\Application Data\cache (以防万一删除)

C:\Documents and Settings\User\Local Settings\Application 数据\Microsoft\Team Foundation

C:\Documents and Settings\User\Local Settings\Application 数据\微软\VisualStudio

C:\Documents and Settings\User\Local Settings\Application 数据\微软\VSCommon

C:\Documents and Settings\User\Local Settings\Application 数据\网站缓存\

C:\Documents and Settings\User\VSWebCache

C:\文档和设置\所有用户\应用程序 Data\Microsoft\VSTAHost\SSIS_ScriptTask\9.0\ItemTemplatesCache

C:\Documents and Settings\All Users\Application Data\Microsoft\VSTAHost\SSIS_ScriptTask\9.0\ProjectTemplatesCache

C:\Documents and Settings\All Users\Application Data\VS\vs10sp1\SetupCache

  • 已删除以下文件:
C:\Documents and Settings\All Users\Application Data\Microsoft\VisualStudio\10.0\vs000223.dat
C:\Documents and Settings\All Users\Application Data\Microsoft\VisualStudio\10.0\1033\devenv.CTM
C:\Documents and Settings\All Users\Application Data\Microsoft\VisualStudio\10.0\1033\ResourceCache.dll
C:\Documents and Settings\All Users\Application Data\Microsoft\VSA\9.0\1033\ResourceCache.dll
C:\Documents and Settings\All Users\Application Data\Microsoft\VSA\9.0\1033\vsaenv10.CTM
C:\Documents and Settings\All Users\Application Data\Microsoft\VSTAHost\SSIS_ScriptComponent\9.0\1033\ResourceCache.dll
C:\Documents and Settings\All Users\Application Data\Microsoft\VSTAHost\SSIS_ScriptTask\9.0\1033\ResourceCache.dll
  • 已清除以下文件夹:
C:\Documents and Settings\User\Local Settings\Temp
  • 我也尝试清除 VS 缓存。我在cmd中执行了以下命令:
cd C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE
devenv /resetuserdata

但没有任何帮助。

我还能做些什么来解决我的奇怪问题? (重装Windows除外)

已编辑:

  1. 更改引用“DllFile.dll”的属性“复制本地”(真/假)没有帮助。

  2. 我尝试创建新的空项目并添加对此库“DllFile.dll”的引用,并且空项目中也存在此错误。所以问题不在我的实际项目中。

【问题讨论】:

    标签: c# visual-studio-2010 visual-studio reference namespaces


    【解决方案1】:

    转到您的解决方案资源管理器并选择显示所有文件。然后来到您的项目 bin 并展开 DllFile.dll 并查看是否有 DllFile.dll.refresh 文件,如果是,则删除并清理解决方案并重建您的项目应该可以成功构建。

    【讨论】:

    • 感谢您的回答!但不幸的是,我的“bin”文件夹不包含“DllFile.dll”,因为在引用属性中,属性“复制本地”设置为“假”。如果我将“复制本地”更改为“真”,则没有任何变化。我的构建错误仍然存​​在。
    • 尝试删除所有 .NET 2.0 框架 dll 并替换它们 .NET 框架 4.0 dll,这样可以消除您收到的警告。
    【解决方案2】:

    这是一个旧错误,即使在 Visual Studio 2019(社区版)中也存在。 IDE 不会更新您从中引用另一个项目的项目文件。但是在设置中,您看到的好像链接在那里。您应该手动添加参考:

    将此写入项目文件(或可以从链接正常工作的另一个项目复制):

      <ItemGroup>
        <ProjectReference Include="...path...\YourProject.csproj" />
      </ItemGroup>
    

    这解决了问题。

    【讨论】:

      猜你喜欢
      • 2011-06-20
      • 1970-01-01
      • 1970-01-01
      • 2011-03-04
      • 1970-01-01
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      相关资源
      最近更新 更多