我已经将 Windows 服务构建为“任何 CPU".为什么它在我的 64 位机器上以 32 位模式运行?

编程入门 行业动态 更新时间:2024-10-28 02:34:30
本文介绍了我已经将 Windows 服务构建为“任何 CPU".为什么它在我的 64 位机器上以 32 位模式运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已将 Windows 服务构建为任何 CPU".但是,当我在 64 位机器上运行它时,它会以 32 位运行.我该如何解决?我使用的是 .NET 和 C#,我的操作系统是 Windows 2008 R2.

I've built a Windows service as "Any CPU". However, when I run it on my 64 bit machine it runs in 32 bit. How can I fix it? I'm using .NET and C#, and my operating system is Windows 2008 R2.

如果我在 x64 中构建它,它会以 64 位模式正确加载.但是,任何 Cpu"——这正是我想要的——以 32 位加载,即使它运行的机器完全支持 64 位.

If I build it in x64 it correctly loads in 64 bit mode. However, "Any Cpu" -- which is what I want -- loads in 32 bit, even though the machine it's running on perfectly supports 64 bit.

编辑以根据反馈添加更多信息

我们确实有第三方工具并参考了 C++ 托管程序集.这些可能是也可能不是为任何 CPU 构建的.事实上,我知道 C++ 托管程序集仅针对 x86 构建.然而,奇怪的是,如果我特别指定 x64,该进程将在 x64 中启动并工作.如果框架试图加载 C++ 托管程序集,它将失败.我不介意这个,因为在代码中,如果我们在 64 位模式下运行,我们不会加载 32 位托管 ++ 程序集.会不会是构建认为,因为这里有一个 32 位程序集,它应该将启动过程(在本例中为 Windows 服务程序集)标记为 x86?

We do have third party tools as well as reference a c++ managed assembly. These may or may not be built for any CPU. In fact i know that the c++ managed assembly is only built for x86. However, the odd things is that if I specifically specify x64 the process will start up and work in x64. If the framework were to attempt to load the c++ managed assembly it would fail. I don't mind this, because in the code, we do not load the 32bit managed ++ assembly if we're running in 64 bit mode. Could it be that the build figures that since there is a 32 bit assembly in here it should mark the launching process (in this case a windows service assembly) as x86?

推荐答案

万一有人遇到我做的同样的事情:我创建了两个新的配置设置(从调试配置复制).出于某种原因,Prefer32Bit"标志设置为 true,即使项目配置页面中的复选框呈灰色且未选中.

In case anybody runs across the same thing I did: I had created two new config settings (copied from the Debug config). For some reason "Prefer32Bit" flag was set to true, even though the checkbox was greyed out and unchecked in the project config page.

您可以通过直接从 .csproj 文件中删除该行来修复它.

You can fix it by removing the line directly from the .csproj file.

<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Staging|AnyCPU'"> <DebugSymbols>true</DebugSymbols> <OutputPath>binStaging</OutputPath> <DefineConstants>DEBUG;TRACE</DefineConstants> <DebugType>full</DebugType> <PlatformTarget>AnyCPU</PlatformTarget> <ErrorReport>prompt</ErrorReport> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <Prefer32Bit>true</Prefer32Bit> <!-- REMOVE THIS LINE --> </PropertyGroup>

更多推荐

我已经将 Windows 服务构建为“任何 CPU".为什么它在我的 64 位机器上以 32 位模式运行?

本文发布于:2023-11-04 17:21:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558555.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:它在   上以   我已经   机器   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!