【问题标题】:Class inclusion error in visual studioVisual Studio 中的类包含错误
【发布时间】:2016-01-31 19:33:32
【问题描述】:

我目前在 Visual Studio 工作,开发基于文本的游戏。我与某个类发生了命名空间冲突。
我有一个类名 Clothing 和命名空间,它也命名为 Clothing。为了解决这个问题,我重命名了命名空间 clothes 而不是服装,然后所有的戏剧都开始了。每当我尝试构建时,我的 csproj 文件都没有更新文件夹中的命名空间引用,我收到以下错误。

[Failure] Could not find file '...\src\Items\Equipment\Apparel\Clothing\Shirts\Shirt.cs'.
[Failure] Could not find file '...\src\Items\Equipment\Apparel\Clothing\ClothingEnum.cs'.
[Failure] Could not find file '...\src\Items\Equipment\Apparel\Clothing\Cloaks\Cloak.cs'.
[Failure] Could not find file '...\src\Items\Equipment\Apparel\Clothing\Boots\JackBoot.cs'.
...

如果我查看这些目录,文件存在但为空。实际文件位于 ...\src\Items\Equipment\Apparel\ Clothes\Boots... 中,它们包含在 csproj 文件中。但是这些文件也在那里。

本质上,我要问的是如何从 csproj 文件中删除这些未使用的引用/依赖项/无论它们是什么。

手动删除 csproj 文件中的 xml 引用只会导致我的项目加载失败。

【问题讨论】:

    标签: c# visual-studio visual-studio-2015 build-error


    【解决方案1】:

    我不明白为什么在重命名命名空间后重命名文件夹 - 在我看来,这是不必要的。

    您可以使用“从项目中排除”从解决方案资源管理器中删除 cs 文件,然后使用“添加 -> 现有项目”添加新文件

    【讨论】:

    • 这很有效,谢谢。我认为命名空间和文件夹名称是相关联的。
    • VS 使命名空间(当它创建 .cs 文件时)遵循文件夹结构以提高可用性和可读性,但保持这种方式并不是强制性的。在许多人从事的一些大型项目中,这一点更为重要。
    猜你喜欢
    • 2011-08-18
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多