# Get UE version in ModuleRules (.Build.cs file)

**URL:** <https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956>\
**Category:** Platform & Builds\
**Tags:** build, unreal-engine, version, question, CPP\
**Created:** [August 23, 2016, 12:43am UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956 "2016-08-23T00:43:38Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![duke22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@duke22](https://forums.unrealengine.com/u/duke22)\
**Post date:** [August 23, 2016, 12:43am UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/1 "2016-08-23T00:43:38Z")

</div>

We’re working with 2 versions of UE4 here due to a bug in the later versions, and I need to be able to check what version to do some conditional stuff in my Build file. Is there a way to do this, ideally with preprocessor checks?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_3922ea43](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_3922ea43](https://forums.unrealengine.com/u/anonymous_user_3922ea43)\
**Post date:** [February 24, 2017, 5:00pm UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/2 "2017-02-24T17:00:06Z")

</div>

Before UE4.14:

```
var VersionFilePath = Path.Combine(UnrealBuildTool.UnrealBuildTool.EngineDirectory.FullName, "Build" + Path.DirectorySeparatorChar + "Build.version");

BuildVersion Version;
if (BuildVersion.TryRead(VersionFilePath, out Version))
{
	if (Version.MajorVersion == X && Version.MinorVersion == Y)
	{
		// do version specific stuff
	}
}

```

After and including UE4.14:

```
BuildVersion Version;
if (BuildVersion.TryRead(out Version))
{
	if (Version.MajorVersion == X && Version.MinorVersion == Y)
	{
		// do version specific stuff
	}
}

```

---

<div class="post-metadata">

**Author:** ![Steazy](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Steazy](https://forums.unrealengine.com/u/Steazy)\
**Post date:** [August 10, 2017, 7:38pm UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/3 "2017-08-10T19:38:57Z")

</div>

This doesn’t answer the question.

This works for C++ files, but not in C# (ie: Build.cs)

---

<div class="post-metadata">

**Author:** ![javidcf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@javidcf](https://forums.unrealengine.com/u/javidcf)\
**Post date:** [July 20, 2018, 11:24am UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/4 "2018-07-20T11:24:35Z")

</div>

In 4.17 Epic introduced C# preprocessor macros for this (see [release notes](https://docs.unrealengine.com/en-us/Support/Builds/ReleaseNotes/4_17#programming)), and you can now conditionally compile blocks with something like:

```
#if UE_4_17_OR_LATER
// Do something
#else
// Do something else
#endif

```

Additionally, from 4.16 the macro `WITH_FORWARDED_MODULE_RULES_CTOR` is also defined. This was intended to decide whether the constructor of your `ModuleRules` subclass should receive a `TargetInfo` (up to 4.15) or a `ReadOnlyTargetRules` (from 4.16). However, you could use it to check for version 4.16 or later too (assuming that macro will not go away in the future…); that is, you could do:

```
#if WITH_FORWARDED_MODULE_RULES_CTOR
#define UE_4_16_OR_LATER
#endf

```

---

<div class="post-metadata">

**Author:** ![FilAl](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FilAl](https://forums.unrealengine.com/u/FilAl)\
**Post date:** [July 24, 2018, 2:34pm UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/5 "2018-07-24T14:34:01Z")

</div>

Dude where did you find this ?!? Please elaborate.

---

<div class="post-metadata">

**Author:** ![javidcf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@javidcf](https://forums.unrealengine.com/u/javidcf)\
**Post date:** [July 24, 2018, 2:42pm UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/6 "2018-07-24T14:42:06Z")

</div>

What exactly? As mentioned, the `UE_4_X_OR_LATER` macros were introduced in the [4.17 release notes](https://docs.unrealengine.com/en-us/Support/Builds/ReleaseNotes/4_17#programming). The macro `WITH_FORWARDED_MODULE_RULES_CTOR` was introduced in the [4.16 release notes](https://docs.unrealengine.com/en-us/Support/Builds/ReleaseNotes/4_16#progamming), as part of the change from `TargetInfo` to `ReadOnlyTargetRules`. I didn’t learn about these from the release notes themselves (I don’t remember where I saw them first, but I think probably in some question on this site), but that is the best reference I could find for them (besides the source code).

---

<div class="post-metadata">

**Author:** ![DevChagrins](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@DevChagrins](https://forums.unrealengine.com/u/DevChagrins)\
**Post date:** [August 4, 2023, 1:54pm UTC](https://forums.unrealengine.com/t/get-ue-version-in-modulerules-build-cs-file/367956/7 "2023-08-04T13:54:06Z")

</div>

I know this will revive this old topic, but as this topic comes up pretty much top of the list on Google, there should be an updated response.

If you want to check the Unreal Engine version in any Build.cs, you can check with Target.Version.

Target.Version.MajorVersion, Target.Version.MinorVersion & Target.Version.PatchVersion are all the parts of the Unreal Engine version.

`Console.WriteLine(String.Format("Unreal version {0}.{1}.{2}", Target.Version.MajorVersion, Target.Version.MinorVersion, Target.Version.PatchVersion));`

You can also use ReadOnlyBuildVersion.Current to get the Version being used, in place of Target.Version. Hopefully this helps someone.
