Is there a way to force an “Any CPU” compiled app to run in 32bit mode on 64bit OS?

后端 未结 2 1295
有刺的猬
有刺的猬 2021-02-19 23:14

If I have a \"Any CPU\" compiled .NET app, it will run in 64bit mode on a 64bit OS.

But if I, for whatever reason, wants to force this app to run in 32bit mode. (As if i

2条回答
  •  情书的邮戳
    2021-02-19 23:40

    I got a new solution!

    Writing a custom .NET host is a better solution for this question. Because host is native applications, if you compile it as 32/64bit app, the assembly it loads will run on 32/64bit mode.

    Don't need to worry about hosting because .NET build processes provide a default host to run .NET applications. In some specialized circumstances, though, it can be useful to explicitly host the .NET runtime.

    So, you can prepare two host (C++ app), one build as 32bit app, the other is 64bit. And make a launch (exe or script) that invoke the host which mode you like. The host will load and run your assembly with the same mode as the host.

    There is a tutoral about Hosting Core CLR: Write a custom .NET Core host to control the .NET runtime from your native code.

    If your assembly is .net framework app, see Hosting the CLR the Right Way.

提交回复
热议问题