举例命名为 XmlToProto(自己替换)
在项目目录/Source/Programs
下新建文件夹 XmlToProto
内部新建文件夹Source,以及5个文件,文件内容见最下方
cmd 运行UBT
..\..\..\..\Engine\Binaries\DotNET\UnrealBuildTool.exe -ProjectFiles XXX\Source\Programs\XmlToProto
会刷新.sln项目文件,之后重新打开VS就可以看到该工程了
可以像正常项目一样引用模块、插件(PublicDependencyModuleNames)
把主流程写到 XmlToProtoMainWindows.cpp 内的main函数内即可(RequestEngineExit之前,且这个函数不能跳过)
新建的代码文件都放到Source里面,不建议分Private和Public
XmlToProto.Build.cs
using UnrealBuildTool;
using System.IO;
using System;
public class XmlToProto : ModuleRules
{
public XmlToProto(ReadOnlyTargetRules Target) : base(Target)
{
PublicDependencyModuleNames.AddRange(
new string[] {
"Core",
}
);
PublicIncludePathModuleNames.AddRange(
new string[] {
"Launch",
"CoreUObject",
"Projects",
"Json",
"ApplicationCore",
}
);
PublicIncludePaths.Add(ModuleDirectory);
bEnableExceptions = true;
bUseUnity = false;
}
}
XmlToProto.Target.cs
using UnrealBuildTool;
using System.Collections.Generic;
public class XmlToProtoTarget : TargetRules
{
public XmlToProtoTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Program;
LinkType = TargetLinkType.Monolithic;
DefaultBuildSettings = BuildSettingsVersion.V2;
LaunchModuleName = "XmlToProto";
ExtraModuleNames.Add("EditorStyle");
// VS内的分类
SolutionDirectory = "GameTools";
bBuildDeveloperTools = false;
// SlateViewer doesn't ever compile with the engine linked in
bCompileAgainstEngine = false;
// We need CoreUObject compiled in as the source code access module requires it
bCompileAgainstCoreUObject = true;
// SlateViewer.exe has no exports, so no need to verify that a .lib and .exp file was emitted by
// the linker.
bHasExports = false;
// Make sure to get all code in SlateEditorStyle compiled in
bBuildDeveloperTools = true;
// UnrealPak is a console application, not a Windows app (sets entry point to main(), instead of WinMain())
bIsBuildingConsoleApplication = true;
}
}
XmlToProtoApp.cpp
#include "XmlToProtoApp.h"
#include "RequiredProgramMainCPPInclude.h"
IMPLEMENT_APPLICATION(XmlToProto, "XmlToProto");
XmlToProtoApp.h
#pragma once
XmlToProtoMainWindows.cpp
#include "CoreMinimal.h"
int main(int argc, char* argv[])
{
RequestEngineExit("Exit normally");
return 0;
}