Can I set LARGEADDRESSAWARE from within Visual Studio?

C#.NetVisual StudioMsbuildLarge Address-Aware

C# Problem Overview


I have a .NET assembly that needs to be 32-Bit and needs to be /LARGEADDRESSAWARE.

I know how to do this with EditBin, but I wonder if there is a built-in way in Visual Studio 2010? Or alternatively, did someone write an MSBuild Task for this?

Edit: This is for a C# app, so no linker options sadly :(

C# Solutions


Solution 1 - C#

Building on @RouMao's answer, you may get an error message saying that editbin cannot be found. Ensure that the environment in the post-build event command line is setup properly by specifying as follows:

call "$(VS100COMNTOOLS)..\tools\vsvars32.bat"
editbin /largeaddressaware $(TargetPath)

Another thing to understand is that your LARGEADDRESSAWARE enabled application will not run in debugging mode when (under the Debug tab in your project properties) the Enable the Visual Studio hosting process check-box is checked (which it is by default), because the vshost.exe is not properly flagged.

Uncheck that box to debug your application using LARGEADDRESSAWARE.

Solution 2 - C#

You can do it as a Post-build task. In "Build Events" tab, put following command

editbin /largeaddressaware $(TargetPath)

into the "Post-build event command line:"

This is the case for VS2008. I think it should work in the same way for VS2010.

Solution 3 - C#

This is a NuGet package that can set LargeAddressAware on your binary after it's built: https://github.com/KirillOsenkov/LargeAddressAware

It doesn't require editbin.exe as it has a managed app to set the flag programmatically: https://github.com/KirillOsenkov/LargeAddressAware/blob/master/SetLargeAddressAware/LargeAddressAware.cs

Update: To use it, just install the package and add this property in your .csproj:

<PropertyGroup>
  <LargeAddressAware>true</LargeAddressAware>
</PropertyGroup>

Solution 4 - C#

If you compile your Assembly with:

<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>true</Prefer32Bit> <!--Default !false!-->

than your resulting assembly will automatically receive LARGE ADDRESS AWARE flag.

Tested with VS 2019 (requires Visual Studio 2015+ as per https://stackoverflow.com/questions/35068309/why-does-any-cpu-prefer-32-bit-allow-me-to-allocate-more-memory-than-x86-und).

So you don't need any special actions in most cases. Your AnyCPU assembly will be executed under x86 + LAA by default.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMichael StumView Question on Stackoverflow
Solution 1 - C#MichaelView Answer on Stackoverflow
Solution 2 - C#Yi ZhaoView Answer on Stackoverflow
Solution 3 - C#Kirill OsenkovView Answer on Stackoverflow
Solution 4 - C#Dmitriy IvanovView Answer on Stackoverflow