【问题标题】:What steps should I take to build and run .net core Web API application in 32-bit environment/runtime?我应该采取哪些步骤在 32 位环境/运行时构建和运行 .net 核心 Web API 应用程序?
【发布时间】:2020-05-26 20:29:10
【问题描述】:

我们使用以下技术开发了一个 .NET Core Web API 应用程序:

-NET Core (3.1)

-Visual Studio 2019

很遗憾,我们不得不将上述应用部署到以下环境:

-32 位环境

-Windows Server 2008 R2 Enterprise (Service Pack 1)

-IIS 7.5 版

-8 GB 内存

因此,在我的 Visual Studio 2019 中,我启动了该应用程序,并采取了以下步骤:

在 VS 中强制 x86 转到属性 > 构建并将平台目标从任何 CPU 更改为 x86

在 .NET Core 应用程序的项目根目录中创建了一个 Directory.Build.targets:

<Project>

      <PropertyGroup

      Condition="'$(OS)' == 'Windows_NT' and

                 '$(PlatformTarget)' == 'x86' and

                 '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and

                 '$(SelfContained)' != 'true'"

                  >

       <RunCommand>$(MSBuildProgramFiles32)\dotnet\dotnet</RunCommand>

      </PropertyGroup>

< /Project >

从 Visual Studio 2019 Developer Command Prompt v16.4.6,我导航到 .NET Core 应用程序的项目根目录。

我跑了:

> >

dotnet clean
...........................
.............

dotnet build


C:\Program
Files\dotnet\sdk\3.1.101\Microsoft.Common.CurrentVersion.targets(2726,5):
error MSB4216: Could not run the "ResolveComReference" task because
MSBuild could not create or connect to a task host with runtime "CLR4"
and architecture "x86".  Please ensure that (1) the requested runtime
and/or architecture are available on the machine, and (2) that the
required executable "C:\Program Files\dotnet\sdk\3.1.101\MSBuild.exe"
exists and can be run.
[D:\ blah blah.csproj]
    6 Warning(s)
    1 Error(s)

Time Elapsed 00:00:04.63'

谁能告诉我如何在 32 位环境中构建和运行这个应用程序?

【问题讨论】:

  • 您确定在运行 dotnet build 的机器上安装了 .net Core 3.1 x86 SDK 吗? (dotnet.microsoft.com/download/dotnet-core/3.1)
  • 您是否尝试过下载 x86 SDK 并使用它(不是 x64 SDK)来构建和发布网络应用程序?

标签: iis .net-core x86 msbuild 32-bit


【解决方案1】:

我应该采取哪些步骤来构建和运行 .net core Web API 在 32 位环境/运行时应用程序?

这很奇怪。 首先,正如akseliomajid所说,尝试安装Net Core 3.1 x86 sdk version

然后,尝试以下步骤:

步骤

1) 在 32 位环境中将构建平台目标更改为 x86

2)当您将项目迁移到32位环境时,请删除解决方案文件夹下的.vs隐藏文件夹bin,obj文件夹。

3)32位环境下打开Developer Command Prompt for VS2019(调用C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe下的msbuild.exe)来构建你的项目。

4) 尝试使用msbuild 而不是dotnet build,因为MSBuild 更强大且编译范围更广。

msbuild xxx.csproj -t:build

msbuild xxx.csproj -t:clean

4) 或将这些节点添加到您的 xxx.csproj 文件中,然后构建您的项目

<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
  <GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
  <GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>

期待任何反馈。

【讨论】:

    【解决方案2】:

    @akseli @omajid @perry-qian-msft @yongqing-yu 对不起,这没用,我们不得不放弃使用 .NET Core 技术(并且必须迁移到 .NET Framework 4.7。 2)因为它会正常工作一会儿,然后给我们500错误,然后是401错误。我认为这与配置有关,因为我们正在使用:

    -NET Core (3.1)

    -IIS 服务器中的进程内

    因此,在独立的 IIS 服务器中,我们不必将 .NET Core (3.1) 应用程序作为“非托管代码”在它自己的应用程序池中运行,因为它都是进程内的,而 .NET Core (3.1) 可以在 IIS 上运行。无论如何,我们没有时间解决这个问题,所以我们迁移到 .NET Framework 4.7.2

    @akseli @omajid @perry-qian-msft @yongqing-yu 谢谢大家的回复。 我的团队技术主管通过在 Visual Studio 2019 中将 .NET Core Web API 应用程序的构建设置指定为“任何 CPU”来找到解决方案。(在 Visual Studio 2019 中,右键单击 .NET Core Web API 应用程序,然后从下拉上下文菜单,然后当窗口窗格出现时,您选择构建选项卡。)

    此外,在 IIS 服务器上,我的团队技术主管确保已部署的 .NET Core Web API 应用程序的应用程序池具有以下设置(请记住,它是“非托管代码”,这一点很重要:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-01
      • 2018-05-14
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多