I had just upgraded to UE 5.7 and Visual Studio 2026. I created a fresh new C++ project using the third person template. When I go to build the project in Visual Studio I keep getting this error:
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: The “SetEnv” task failed unexpectedly.
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: System.ArgumentException: Environment variable name or value is too long.
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: at System.Environment.SetEnvironmentVariable(String variable, String value)
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: at System.Environment.SetEnvironmentVariable(String variable, String value, EnvironmentVariableTarget target)
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: at Microsoft.Build.CPPTasks.SetEnv.Execute()
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Execute()
1>C:\Program Files\Microsoft Visual Studio\18\Community\MSBuild\Microsoft\VC\v180\Microsoft.Cpp.Current.targets(102,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.d__26.MoveNext()
I do see that the project has very long paths in include directories and source directories under project properties → configuration properties → VC++ directories → include directories and source directories.
Those paths in your log do look a bit long, and the most straightforward solution would be to reduce them as much as possible. In order to do so, you would need to move your UE install, and your project’s location, to different locations.
Start with the engine, moving to your root, with a very short folder containing it (for example, C:\UE57). Then do the same with the project, as short as possible (something like C:\Projs\Game1)
Once you complete the move, please make sure you right click your .uproject file, and select “Generate Visual Studio Project Files”. Additionally, if UE pops up with any conflict regarding the move, a reinstall to the new location would be the best method to resolve that.
My path for the project is D:\UnrealEngine5\UnrealProjects\BattleBlaster and the path for the engine is D:\Epic Games\UE_5.7\Engine. I dont think they’re as long that they should give an error.
I did read that it has something to do with my include directories setting for the project. Unreal injects hundreds of paths to the include directories, and the setenv function is trying to include all of those paths, and that is what’s causing the failure.
My question is why in the first place unreal inject all these paths? And would removing them do anything to my project?
@COLD_BLOOD4 Definitely not an expert in UE+VS, but faced the same issue as you. I tried a bunch of things, but my installation was already at the disk level.
What worked for me was deleting the VS project and using a different IDE that works directly with the project file (not the .sln one).
I also noticed UE was generating includes that did not exist in my installation for 5.7.
This fixes the build, but has the unfortunate side effect that Intellisense suddenly doesn’t know where to look for any engine includes, so it starts flagging all your code with red squigglies.
The same thing happened to me when I did that. I don’t know why this would happen, why would unreal all of a sudden inject a bunch of paths to the include directories? And is there no way to fix it where everything will work
You don’t have to clean them all,just remove some of those entries till you can build the sln,it seems to be a vs2026 bug which it can’t handle too many of include paths.
I recently encountered the same error while building my project from Visual Studio:
After some investigation, I noticed that the Unreal Engine Integration Configuration inside Visual Studio now exposes a setting called Max Include Paths Length (chars). This setting corresponds to the MaxSharedIncludePaths field inside BuildConfiguration.xml (located under UnrealBuildTool/BuildConfiguration, as shown in the screenshot blow).
Solution:
I removed all MaxSharedIncludePaths entries from every BuildConfiguration.xml, deleted the generated .sln, and regenerated the solution. After doing so, the build completed normally and the MSBuild SetEnv error no longer occurred.
Thanks for the reply, but i only see 1 buildConfiguration.xml file and it didn’t have that line regrading the MaxSharedIncludePaths.
What is weird is I even tried uninstalling everything and reinstalling VS 2022 and UE 5.6.1, for some reason it still happened, I got the same error. Then today it started working building from the IDE. However now that I try to open the uproject it gives me this
I tried everything, the binaries, intermediate, derivedcache, saved folders, regenerating the solution files, building from source. Nothing worked. I’m left with uninstalling UE, uninstalling the epic launcher, and trying from scratch, this is the worst. I wish someone from Epic would comment on this
I resolved this issue by deleting %AppData%\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml
Then re-generating the project from the editor. I’m still having other issues with VS2026 and Unreal, personally. But I just keep VS2022 installed alongside it.