Tuesday 16 March 2021

Setting LargeAddressAware in VisualStudio 2019

 Introduction

We write a lot of applications that use a 32bit dll, so we have to compile them as x86 builds. But they also load very large data files so we need to set the LargeAddressAware flag on the executable. While we were using .net Framework we used the LargeAddressAware nuget package and it worked great. This gets us over the 2Gb limit and ensures we don't get out of memory problems.

After starting to create .Net Core applications and we've found that this method no longer works. The setting of the LargeAddressFlag needs to be set on the executable, but the nuget package now applies this to the dll.

Setting the flag in Core

We're had to fall-back to creating our own post-build processing that uses the macros to build the location to the compiled executable. Here's how we did it:-

  1. Go to your project property settings and select the Build Events page.

  2. Enter the following code into the Post-build event command line.

call "$(DevEnvDir)..\tools\VsDevCmd.bat"
editbin /LARGEADDRESSAWARE "$(TargetDir)$(TargetName).exe"

The first line adds editbin to the path, and this is correct for Visual Studio 2019. At some stage this may need to be updated, and older versions of Visual Studio probably won't work.

LargeAddressAware added in Post-Build