So I’ve gotten through 90% of the hump to migrate a UE4 C++ Project to UE5.
However, I have one last issue with a plugin (which is absolutely a must-have for the project) that is not playing happy with the build tool.
This plugin’s .Build.cs file uses System.Text.RegularExpressions to invoke some Regex and it seems to be upsetting the UE5 Build Tool for some reason.
error CS1069: The type name 'Regex' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
The error message
error CS1069: The type name ‘Regex’ could not be found in the namespace ‘System.Text.RegularExpressions’.
This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=4.2.2.0,
The error may be due to the fact that Version=4.2.2.0 is looking for does not exist, or 4.3does not exist in Unreal 5.0EA
see C:\Users\Owner\source\repos\UE50EA\Engine\Binaries\ThirdParty\DotNet\Windows\sdk\3.1.403\Microsoft\Microsoft.NET.Build.Extensions\net461\lib
and UE4 probably uses 4.2.2.0 which is very old
Unfortunately, I have tried the following and am still getting the same output on the UBT:
Updated System.Text.RegularExpressions with the latest NuGet package’s version (I noticed using IL DASM even then that DLL version is only 4.1.0.0)
Updated .NET (already at 5.0 on my local)
Installed VS Build Tools, as I heard on some other UE issues that that helped.
Updated the C# file itself to move the includes around.
Still no luck sadly, still get the error
error CS1069: The type name 'Regex' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
Is there a way to check what .NET Version is being targeted by the UBT, or any other configuration which may be missing?
On the left is my Visual Studio 2019 Showing all the .NET SDK and targeting packs
On the right is Windows Features in Windows 10 and in the bottom right is the .NET Core Frameworks loaded directories stored in C:\Windows\Microsoft.NET\Framework.
I suspect the problem is something missing is the Visual Studio 2019 as that what has happened in past.
I checked my Windows Features which looks identical to yours, and I also updated VS 2019 to include the above targeting packs (although most were there).
Unfortunately non helped. Exact same issue.
I suspect I will be waiting for Epic to release an update to 5.0EA. Unfortunately, I haven’t come across anyone else with this issue so it’s really hard to see if it is on their radar or not.
We are seeing the exact same issue with UE5 EarlyAccess and RegEx.
I’ve added a question on my own as I couldn’t find anything similar at the time of writing (link here).
I just wanted to let you know we are struggling with the same and we still have no resolution.
Waiting for Epic to respond and in the meantime, we will try to replace our regex usages with non-regex equivalent
If you are building from source, then you can fix this by modifying to /Engine/Source/Programs/UnrealBuildTool/System/DynamicCompilation.cs.
Inside UnrealBuildTool.DynamicCompilation.CompileAssembly(...) (somewhere around Line 230) is where several reference assemblies are specified.
We can add our dependency like this:
Thanks for the feedback. I have made the change into the file located at ...\UE_5.0EA\Engine\Source\Programs\UnrealBuildTool\System\DynamicCompilation.cs and yet I am still getting the build error:
ERROR: ...\Plugins\<PLUGIN_NAME>\Source\<PLUGIN_NAME>\<PLUGIN_NAME>.Build.cs(70,31): error CS1069: The type name 'Regex' could not be found in the namespace 'System.Text.RegularExpressions'. This type has been forwarded to assembly 'System.Text.RegularExpressions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' Consider adding a reference to that assembly.
ERROR: Expecting to find a type to be declared in a target rules named 'GameNameTarget'. This type must derive from the 'TargetRules' type defined by Unreal Build Tool.
Do I need to do anything else to rebuild UnrealBuildTool?
Just a quick heads up and a big thanks: Your solution worked like a charm. I did have to ensure that the project of UBT is rebuilt by cleaning and building it manually. Once that was done I was able to generate the project files just fine!
I did a password recovery process on this account in order to post a comment here…
THIS IS THE SOLUTION!
Paste that MetadataReferences.Add(MetadataReference.CreateFromFile(Assembly.Load("System.Text.RegularExpressions").Location)); right in that list of MetadataReferences pile.