我已经将Windows服务构建为“任何CPU”。为什么它在我的64位计算机上以32位模式运行? [英] I've built a Windows service as "Any CPU". Why does it run in 32-bit mode on my 64 bit machine?

查看:309
本文介绍了我已经将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位模式运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆