我可以在 Visual Studio 中设置 LARGEADDRESSAWARE 吗?
我有一个 .NET 程序集,需要是 32 位并且需要是 /LARGEADDRESSAWARE
。
我知道如何使用 EditBin
执行此操作,但我想知道 Visual Studio 2010 中是否有内置方法?或者,有人为此编写了 MSBuild 任务吗?
编辑:这是针对 C# 应用程序的,因此遗憾的是没有链接器选项:(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 @RouMao 的回答,您可能会收到一条错误消息,指出无法找到 editbin。通过如下指定确保正确设置构建后事件命令行中的环境:
另一件需要理解的事情是,启用了
LARGEADDRESSAWARE
的应用程序将不会在调试模式下运行(在项目属性中的“调试”选项卡)中的“启用 Visual Studio 托管进程”复选框已选中(默认情况下),因为
vshost.exe
未正确标记。取消选中该框可使用
LARGEADDRESSAWARE
调试您的应用程序。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:
Another thing to understand is that your
LARGEADDRESSAWARE
enabled application will not run in debugging mode when (under theDebug
tab in your project properties) theEnable the Visual Studio hosting process
check-box is checked (which it is by default), because thevshost.exe
is not properly flagged.Uncheck that box to debug your application using
LARGEADDRESSAWARE
.您可以将其作为构建后任务来完成。在“Build Events”选项卡中,将以下命令
放入“Post-build event command line”中:
VS2008 就是这种情况。我认为VS2010应该以同样的方式工作。
You can do it as a Post-build task. In "Build Events" tab, put following command
into the "Post-build event command line:"
This is the case for VS2008. I think it should work in the same way for VS2010.
这是一个 NuGet 包,可以在构建二进制文件后在其上设置 LargeAddressAware: https://github.com/KirillOsenkov/LargeAddressAware
它不需要 editbin.exe,因为它有一个托管应用程序以编程方式设置标志: https://github.com/KirillOsenkov/LargeAddressAware/blob/master/SetLargeAddressAware/LargeAddressAware.cs
更新:
要使用它,只需安装该包并将此属性添加到您的 .csproj 中:
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:
如果您使用以下命令编译程序集:
那么生成的程序集将自动接收
LARGE ADDRESS AWARE
标志。使用 VS 2019 进行测试(需要 Visual Studio 2015+,按照 为什么“任何 CPU(首选 32 位)”允许我在 .NET 4.5 下分配比 x86 更多的内存?)。
因此,在大多数情况下您不需要任何特殊操作。默认情况下,您的 AnyCPU 程序集将在 x86 + LAA 下执行。
If you compile your Assembly with:
than your resulting assembly will automatically receive
LARGE ADDRESS AWARE
flag.Tested with VS 2019 (requires Visual Studio 2015+ as per Why does 'Any CPU (prefer 32-bit)' allow me to allocate more memory than x86 under .NET 4.5?).
So you don't need any special actions in most cases. Your AnyCPU assembly will be executed under x86 + LAA by default.