Skip to content

Add support for Visual Studio 2022 #253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 15, 2022
Merged

Conversation

jonpas
Copy link
Contributor

@jonpas jonpas commented May 11, 2022

RunUAT will print the following message with 4.27.2 (and older), but it still works. UE 5.0 (presumably) updated that version check as they increment it with every release if there is a newer compatible VS version.

Detected compiler newer than Visual Studio 2019, please update min version checking in WindowsPlatformCompilerSetup.h

I also defaulted it to VS2019. VS2017 is pretty old and certain C++17 features are not well supported - this comes into play if you are building 3rd party things along with your Unreal project. Wanted to default to VS2022, but VS2019 feels safer at this time.

Minimal supported Unreal version for VS2022 might be higher, but I can't really test all older Unreal versions at this time. Since VS2019 to VS2022 generally worked without issue, I am assuming it is compatible to the same range of engines backwards as VS2019 is.

I didn't test the full build yet.


As a side note, RunUAT still needs to be used with -VS2019 argument (eg. ue4 package -VS2019) to pick up VS2022 and prevent it from complaining about missing VS2017. That is something that should be documented in ue4cli if this is confirmed working.

@jonpas
Copy link
Contributor Author

jonpas commented May 11, 2022

Run with VS2022 on GitHub CI: https://github.com/jonpas/ue4-docker/runs/6395495344

Fails on VS installation, will be poking at this over the next few days.

@slonopotamus
Copy link
Collaborator

There are issues with MS infra today, so CI failure could be unrelated to your changes.

@jonpas
Copy link
Contributor Author

jonpas commented May 12, 2022

build-prerequisites target built successfully on all versions: https://github.com/jonpas/ue4-docker/actions/runs/2312808229

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 12, 2022

I've started ue4-docker build --visual-studio=2022 --target=minimal 5.0.1 against this PR, but it will take some time (runs on a HDD).

@jonpas
Copy link
Contributor Author

jonpas commented May 12, 2022

Sounds good, I am going to start a build on 4.27 soon here:

ue4-docker build 4.27.2 -isolation=process --target=full --visual-studio 2022 --exclude debug --exclude templates --monitor`

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

I've started ue4-docker build --visual-studio=2022 --target=minimal 5.0.1 against this PR, but it will take some time (runs on a HDD).

Failed with Could not find NetFxSDK install dir; this will prevent SwarmInterface from installing. Install a version of .NET Framework SDK at 4.6.0 or higher..

I think we should replace Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools with Microsoft.Net.ComponentGroup.DevelopmentPrerequisites here. This will slightly affect .NET versions (4.6.1 vs 4.6.2, 4.7 vs 4.7.2) for VS2017/VS2019, but that shouldn't introduce any issues.

No, we can't change that because UE4 explicitly requires 4.6.2, so 4.6.1 won't work.

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

I am getting this on 4.27.2:

C:\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1221,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6.2 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\UnrealEngine\Engine\Source\Programs\AutomationToolLauncher\AutomationToolLauncher.csproj]

Tried adding Microsoft.Net.Component.4.6.TargetingPack, but no avail.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

Tried adding Microsoft.Net.Component.4.6.TargetingPack, but no avail.

Possibly Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools will work instead. We can't use random 4.6.x because UE4 explicitly requires 4.6.2.

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

Trying Microsoft.Net.Component.4.6.2.TargetingPack now.

Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools

Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools is already installed and I am getting that error though.

@slonopotamus
Copy link
Collaborator

Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools is already installed and I am getting that error though.

No-no. There ain't such thing as Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools for VS2022 Build Tools!

I literally talk about Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools component name.

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

Ooooh... those pages are so confusing to navigate. I was looking at the VS2019 one. 🤦

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools worked, on to the next error!

Step 14/26 : RUN .\Engine\Build\BatchFiles\RunUAT.bat BuildGraph     -target="Make Installed Build Win64"     -script=Engine/Build/InstalledEngineBuild.xml     -set:WithDDC=true     -set:HostPlatformOnly=true -set:VS2022=true &&    (if exist C:\UnrealEngine\LocalBuilds\InstalledDDC rmdir /s /q C:\UnrealEngine\LocalBuilds\InstalledDDC) && echo. && echo.RUN directive complete. Docker will now commit the filesystem layer to disk. && echo.Note that for large filesystem layers this can take quite some time. && echo.Performing filesystem layer commit... && echo.
 ---> Running in e3de8adf9596
Running AutomationTool...
Parsing command line: BuildGraph -target="Make Installed Build Win64" -script=Engine/Build/InstalledEngineBuild.xml -set:WithDDC=true -set:HostPlatformOnly=true -set:VS2022=true -compile
[ue4-docker build] [2022-05-13 14:10:25] [Available disk: 805.93 GiB] [Available memory: 26.67 GiB physical, 5.00 GiB virtual] [CPU usage: 21.60%]
Dependencies are out of date. Compiling scripts....
  FastJSON\Getters.cs(5,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  FastJSON\Getters.cs(16,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  FastJSON\JSON.cs(13,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  FastJSON\JSON.cs(903,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  Perforce\PerforceError.cs(11,26): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  Perforce\PerforceError.cs(47,26): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
  CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj]
Took 2.6784616s to run MSBuild.exe, ExitCode=1
ERROR: Failed to build "C:/UnrealEngine/Engine/Programs/AutomationTool/Saved\UATTempProj.proj":
       FastJSON\Getters.cs(5,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       FastJSON\Getters.cs(16,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       FastJSON\JSON.cs(13,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       FastJSON\JSON.cs(903,25): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       Perforce\PerforceError.cs(11,26): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       Perforce\PerforceError.cs(47,26): warning CS1692: Invalid number [C:\UnrealEngine\Engine\Source\Programs\DotNETCommon\DotNETUtilities\DotNETUtilities.csproj]
       CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj]

       (see C:\UnrealEngine\Engine\Programs\AutomationTool\Saved\Logs\Log.txt for full exception trace)
AutomationTool exiting with ExitCode=1 (Error_Unknown)
BUILD FAILED

No clue where that comes from.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

  CSC : error CS1617: Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default [C:\UnrealEngine\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.csproj]

It's this: https://github.com/EpicGames/UnrealEngine/blob/4.27/Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj#L51-L52

    <!-- The mono compiler used to ship on Mac is only compatible with version 6 -->
    <LangVersion>6</LangVersion>

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

Apparently Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools in VS2022 gives us such compiler that is too old and doesn't talk C# 6. So it looks like it isn't equivalent to what we get on VS2017/VS2019 via Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools

@slonopotamus
Copy link
Collaborator

I'm not sure how that is possible. C# 6 support has to be in .NET 4.6, according to Wikipedia.

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

I was just about to say that. 🤔

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

Okaay, another approach: remove Microsoft.Net.ComponentGroup.4.6.2-4.7.1.DeveloperTools, add Microsoft.Net.Component.4.6.2.TargetingPack PLUS Microsoft.Net.Component.4.8.SDK. When I was adding VS2019 support, I discovered that VS2019 installs 4.8 SDK when you request Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools, so we're trying to repeat that on top of VS2022 now.

Note that we still need to list Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools for VS2017 because it doesn't have .NET 4.8.

But I am still completely puzzled where we get pre-C#6 compiler from.

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

I will attempt that.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 13, 2022

So, the plan is:

VS2017 will react to Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools and Microsoft.Net.Component.4.6.2.TargetingPack (the latter is redundant). It ignores Microsoft.Net.Component.4.8.SDK because VS2017 doesn't have that. What will get installed is 4.6 SDK + 4.6.2 targeting pack.

VS2019 will react to all Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools, Microsoft.Net.Component.4.6.2.TargetingPack and Microsoft.Net.Component.4.8.SDK. Only first one matters, others are redundant. What will get installed is 4.8 SDK + 4.6.2 targeting pack. VS2019 doesn't have 4.6 SDK, so we only end up with a single SDK.

VS2022 will react to Microsoft.Net.Component.4.6.2.TargetingPack + Microsoft.Net.Component.4.8.SDK. Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools is ignored because VS2022 doesn't have that. What will get installed is 4.8 SDK + 4.6.2 targeting pack (identical to VS2019).

If you have simpler ways to get a working 4.6.2 toolchain across multiple VS versions, I'm all ears :D

@jonpas
Copy link
Contributor Author

jonpas commented May 13, 2022

Worked to the same point, still the same C#6 error. I am really confused what it's picking up.

If you have simpler ways to get a working 4.6.2 toolchain across multiple VS versions, I'm all ears :D

It's a mess.

@slonopotamus
Copy link
Collaborator

Weird.

This is what I have inside ue4-build-prerequisites with VS2022 + Microsoft.Net.Component.4.6.2.TargetingPack + Microsoft.Net.Component.4.8.SDK:

image

And their versions...

image

@slonopotamus
Copy link
Collaborator

I'm starting a new attempt:

Remove Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools
Add Microsoft.Net.Component.4.6.2.TargetingPack and Microsoft.Net.ComponentGroup.DevelopmentPrerequisites

The motivation behind this combo is that we ask the beast to install whatever compiler is the best on given VS version plus our target SDK.

If this works, we'll need to retest VS2017 because its docs say that Microsoft.Net.ComponentGroup.DevelopmentPrerequisites installs ".NET Framework 4.6.1 development tools" and I am not sure whether it is good enough for 4.6.2.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 15, 2022

VS2022 cannot even compile UE-5.0.1:

C:\UnrealEngine\Engine\Source\Runtime\Core\Private\IO\IoStore.cpp(2316) : fatal error C1001: Internal compiler error.
(compiler file 'D:\a\_work\1\s\src\vctools\Compiler\Utc\src\p2\main.c', line 220)
 To work around this problem, try simplifying or changing the program near the locations listed above.
If possible please provide a repro here: https://developercommunity.visualstudio.com
Please choose the Technical Support command on the Visual C++
 Help menu, or open the Technical Support help file for more information
  cl!RaiseException()+0x69
  cl!RaiseException()+0x69
  cl!CloseTypeServerPDB()+0x2a4e3
  cl!CloseTypeServerPDB()+0xeeecb

According to this, 4.27 is also affected.

@slonopotamus
Copy link
Collaborator

Remove Microsoft.Net.ComponentGroup.4.6.2.DeveloperTools
Add Microsoft.Net.Component.4.6.2.TargetingPack and Microsoft.Net.ComponentGroup.DevelopmentPrerequisites

BTW, this seems like the way to go. I'll retest VS2017 + something old (like UE-4.20) and if that works, we'll declare .NET solved.

@jonpas
Copy link
Contributor Author

jonpas commented May 15, 2022

Nice job on .NET!

I guess VS2022 support can still be merged for whenever engine compilation in UE5 is fixed?

@jonpas
Copy link
Contributor Author

jonpas commented May 15, 2022

https://developercommunity.visualstudio.com/t/vs2022-1710-internal-compiler-error-when-building-1/1677086#T-N1686947

We could potentially apply this as a patch in ue4-source or ue4-minimal?

@slonopotamus
Copy link
Collaborator

I'll retest VS2017 + something old (like UE-4.20)

And it just works

@slonopotamus slonopotamus merged commit 55be232 into adamrehn:master May 15, 2022
@jonpas jonpas deleted the vs2022 branch May 15, 2022 19:36
@slonopotamus
Copy link
Collaborator

slonopotamus commented May 15, 2022

We could potentially apply this as a patch in ue4-source or ue4-minimal?

After reading the whole thread, I'm under impression that people get cl.exe crashes even with the patch. But possibly I'm reading it wrong.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 15, 2022

So, you could start another round of testing to see whether that patch actually fixes things. The proper solution is of course to fix crash on VS side.

@slonopotamus
Copy link
Collaborator

P.S. I merged this PR anyway because I believe that eventually VS crash will be fixed, and all changes that were done here make sense.

@jonpas
Copy link
Contributor Author

jonpas commented May 15, 2022

Thanks @slonopotamus!


There is an open PR to fix it in 5.0: https://github.com/EpicGames/UnrealEngine/pull/9043

I will try to apply it to UE 4.27 and see what happens either way.

@jonpas
Copy link
Contributor Author

jonpas commented May 16, 2022

I just ran a build with latest .NET changes on VS2022 and got the same C#6 error. Did you run it with VS2022 or just with VS2019 and VS2017?

@slonopotamus
Copy link
Collaborator

I ran:

  1. VS2022 + UE-5.0.1 (and ended up with that compilation failure)
  2. VS2019 + UE-4.27.2
  3. VS2017 + UE-4.20.3

@jonpas
Copy link
Contributor Author

jonpas commented May 16, 2022

Rgr, thanks 👍

VS2022 + UE-4.27.2 seems to still have issues. Not sure I'll spend too much time on it, UE5 is ultimately the goal for VS2022 anyways.

@slonopotamus
Copy link
Collaborator

I've tried VS2022 + UE-4.27.2 and also observe C#6 error. Weird. I am completely out of ideas how to set up .NET in VS2022 Build Tools.

@slonopotamus
Copy link
Collaborator

slonopotamus commented May 16, 2022

Last try: --add Microsoft.NetCore.Component.SDK No, it's .NET Core.

@jonpas
Copy link
Contributor Author

jonpas commented May 16, 2022

I've tried VS2022 + UE-4.27.2 and also observe C#6 error.

That sounds like an issue in UE-4.27.2 as it doesn't happen in UE-5.0.1, maybe it's not an issue with our setup of .NET at all.

@TBBle
Copy link
Collaborator

TBBle commented May 16, 2022

C# 6 should work with .NET 4.6 (and older as well), but it's probably something in the UE environment that's pointing at an older compiler version, or an old MSBuild version is being picked up.

Based on this blog post, a C# 5 compiler means we're using the C++-based compiler bundled with .NET Framework, not the Roslyn compiler which comes with Visual Studio 2015+ or can be installed into a project with NuGet.

Poking around, perhaps we also need to install something like "C# and Visual Basic Roslyn compilers" (Microsoft.VisualStudio.Component.Roslyn.Compiler in VS2022). Microsoft.VisualStudio.Workload.MSBuildTools should have pulled that in though (as well as a matching MSBuild version), which is why the wrong MSBuild version being first in the PATH seems more likely (as that'd not know about the new Roslyn compiler, and use the .NET-bundled one instead).

So it might be as simple as adding the right path to PATH so that the right MSBuild is chosen. Do the attempt logs record the MSBuild version that was being run? I don't see it in the console output with the /langversion failure, but maybe the more-detailed logs it mentions there included that.

Also worth noting that last time we saw this problem (VS2019 in 4.22) the fix was ensuring the right MSBuild was found. However, GetMSBuildPath.bat hasn't changed between 4.27.2 and 5.0.1 so it's probably not a missing update in that script this time.

And apparently by "we" I mean April 2019 me... O_O

@jonpas
Copy link
Contributor Author

jonpas commented May 18, 2022

Here is the diff to the Internal compiler error patch for VS2022. Same as in https://github.com/EpicGames/UnrealEngine/pull/9043.

However it doesn't fix the missing .NET 4.5 in VS2022 Build Tools that Unreal Engine still requires.

UE-5.0.2 will fix IoStore.cpp and json=1.2 (a newer VS2022 issue), but there is no movement regarding .NET 4.5.

@CanisHelix
Copy link
Contributor

Tried building 5.1.0 using the following command: (other than visual-studio=2022 this should match the official Linux builds Adam does).

ue4-docker build 5.1.0 --visual-studio=2022 --exclude debug --exclude templates --exclude ddc --monitor --opt disable-labels --opt enable-dso-patch --opt buildgraph-args="-set:WithClient=true -set:WithServer=true"

It failed eventually with the following:

C:\BuildTools\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(1229,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.5 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks [C:\UnrealEngine\Engine\Saved\CsTools\Engine\Source\Programs\NetworkProfiler\NetworkProfiler\NetworkProfiler.csproj]
Took 2.0856453999999998s to run MSBuild.exe, ExitCode=1
Command failed (Result:1): C:\BuildTools\MSBuild\Current\Bin\MSBuild.exe C:\UnrealEngine\Engine\Saved\CsTools\Engine\Source\Programs\NetworkProfiler\NetworkProfiler\NetworkProfiler.csproj /property:Platform=AnyCPU /property:Configuration=Development /restore /verbosity:minimal /nologo. See logfile for details: 'MSBuild-2022.11.18-14.13.26.txt'
AutomationTool executed for 5h 34m 18s
AutomationTool exiting with ExitCode=1 (Error_Unknown)
BUILD FAILED

I had this same problem locally on my PC and followed the instructions at https://dev.epicgames.com/community/learning/tutorials/k8Ve/unreal-engine-how-to-build-the-unreal-editor-github to install 4.5 as apparently this requires a special method as the vs-installer won't install it and the msi has gone from MS's website.

[ Visual Studio 2022 only ], you will also need to do the following:
Manually install the  ".Net 4.5 Framework Pack" ( Developer Pack and Runtime ):
Download Microsoft.NETFramework.ReferenceAssemblies.net45 from nuget.org
Open the package as zip
Copy the files from build\.NETFramework\v4.5\ to C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5
For more details: Building a project that target .NET Framework 4.5 in Visual Studio 2022

Doing this I was able to build locally, so this would need to be done inside the Containers when using VS 2022 too.

@slonopotamus
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants