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

编程入门 行业动态 更新时间:2024-10-27 20:26:18
本文介绍了我已经将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位模式加载。但是, Any 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位托管++程序集。

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>bin\Staging\</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:24:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1558558.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:它在   上以   我已经   模式   计算机

发布评论

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

>www.elefans.com

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