【问题标题】:Build.cs not working even after being restores to it's previous versionBuild.cs 即使在恢复到以前的版本后也无法工作
【发布时间】:2022-06-15 13:10:26
【问题描述】:

我正在尝试编译我正在处理的项目,但弹出以下错误消息:

Invalidating makefile for SpaceShooterEditor (SpaceShooter.Build.cs modified)
While compiling E:\ue projects\SpaceShooter\Intermediate\Build\BuildRules\SpaceShooterModuleRules.dll:
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(3,29) : error CS0246: The type or namespace name 'ModuleRules' could not be found (are you missing a using directive or an assembly reference?)
e:\ue projects\SpaceShooter\Source\SpaceShooter\SpaceShooter.Build.cs(5,25) : error CS0246: The type or namespace name 'ReadOnlyTargetRules' could not be found (are you missing a using directive or an assembly reference?)
ERROR: Unable to compile source files.

知道为什么会发生这种情况吗?昨晚我试图编写一个小部件,修改了 build.cs,然后用以前工作的 build.cs 替换了修改后的版本(它破坏了游戏),但仍然没有?有没有希望让它发挥作用,还是我应该重新开始?还有,如何避免呢?

我已经进行了重新启动和刷新。我什至去删除了二进制文件和一些已兑现的文件,但没有用。

您将在下面找到 Build.cs 的内容:


public class SpaceShooter : ModuleRules
{
    public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
    {
        PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

        PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

        PrivateDependencyModuleNames.AddRange(new string[] { });

        // Uncomment if you are using Slate UI
        // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

        // Uncomment if you are using online features
        // PrivateDependencyModuleNames.Add("OnlineSubsystem");

        // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
    }
}

当我尝试输入指定 using UnrealBuildTool; 时,Visual Studio 出于某种原因,在我点击编译或保存时将其删除。

【问题讨论】:

  • 用以前的版本替换文件时是否出现不同的错误?
  • 不幸的是,没有。同样的错误。我会尽快发布上述构建文件的内容。

标签: c# unreal-engine4


【解决方案1】:

由于您不共享 Build.cs 文件中包含的内容,因此我将仅解释错误是什么以及如何修复它。该错误基本上表明它无法根据第 29 行和第 25 行编译 Build.cs 文件,并且在那里使用的类型称为“ModuleRules”和“ReadOnlyTargetRules”在任何命名空间中都找不到包含在 Build.cs 顶部的 using 语句中。这些类型都存储在 UnrealBuildTool 命名空间中,因此可以通过键入以下内容将其包含在您的文件中:

using UnrealBuildTool;

然而,这似乎是解决您的问题的一个微不足道的解决方案,但由于您不分享很多信息,这是我目前可以为您提供的最佳解决方案。

【讨论】:

  • 感谢您的回答。我更新了我的问题以显示 build.cs 的内容
【解决方案2】:

经过一番挖掘,我发现将内容包装在 namespace UnrealBuidTool.Rules{} 中可以解决这个问题。最后,构建文件如下所示:

namespace UnrealBuildTool.Rules
{
    public class SpaceShooter : ModuleRules
    {
        public SpaceShooter(ReadOnlyTargetRules Target) : base(Target)
        {
            PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;

            PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

            PrivateDependencyModuleNames.AddRange(new string[] { });

            // Uncomment if you are using Slate UI
            // PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });

            // Uncomment if you are using online features
            // PrivateDependencyModuleNames.Add("OnlineSubsystem");

            // To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
        }
    }
}

【讨论】:

    猜你喜欢
    • 2011-10-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-27
    • 2019-01-20
    • 2021-11-26
    • 2014-07-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多