问题
We developed an a .NET Core Web API application using the following technologies:
-NET Core (3.1)
-Visual Studio 2019
Unfortunately, we have to deploy said application to the following environment:
-32-bit Environment
-Windows Server 2008 R2 Enterprise (Service Pack 1)
-IIS Version 7.5
-8 GB RAM
Therefore, within my Visual Studio 2019, I brought up the application, and took the following steps:
Force x86 in VS go to the Properties > Build and change Platform target from Any CPU to x86
Created a Directory.Build.targets in the the .NET Core application's Project root directory:
<Project> <PropertyGroup Condition="'$(OS)' == 'Windows_NT' and '$(PlatformTarget)' == 'x86' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and '$(SelfContained)' != 'true'" > <RunCommand>$(MSBuildProgramFiles32)\dotnet\dotnet</RunCommand> </PropertyGroup> < /Project >
From Visual Studio 2019 Developer Command Prompt v16.4.6, I navigated to the .NET Core application's Project root directory.
I ran:
> >
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'
Could someone please tell me how I can build and run this application in a 32-bit environment?
回答1:
What steps should I take to build and run .net core Web API application in 32-bit environment/runtime?
It is quite strange. First, just as akseli and omajid said, try to install Net Core 3.1 x86 sdk version.
Then, try the following steps:
Steps
1) change build platform target to x86
in 32-bit environment.
2) when you migrate the project into 32-bit environment, please delete .vs
hidden folder which exists under the solution folder, bin
, obj
folder.
3) open Developer Command Prompt for VS2019 in 32-bit environment(it call the msbuild.exe
under C:\Program Files\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
) to build your project.
4) try to use msbuild
rather than dotnet build
since MSBuild is more powerful and has a wider range of compilations.
msbuild xxx.csproj -t:build
msbuild xxx.csproj -t:clean
4) or add these node in your xxx.csproj
file then build your project
<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Core'">
<GenerateResourceMSBuildArchitecture>CurrentArchitecture</GenerateResourceMSBuildArchitecture>
<GenerateResourceMSBuildRuntime>CurrentRuntime</GenerateResourceMSBuildRuntime>
</PropertyGroup>
Any feedback will be expected.
回答2:
@akseli @omajid @perry-qian-msft @yongqing-yu All Thank you for all your responses. My Team Tech Lead found the solution by specifying the .NET Core Web API Application's Build Settings to "Any CPU" Within Visual Studio 2019. ( Within Visual Studio 2019, Right-click on .NET Core Web API Application, and then choose properties from the drop-down context menu, and then when the window pane shows up on, you select the Build Tab. )
Also, on the IIS Server, my Team Tech Lead ensured that that deployed .NET Core Web API Application's Application pool had the following settings( important to keep in mind that it is "Not Managed Code":
来源:https://stackoverflow.com/questions/62030884/what-steps-should-i-take-to-build-and-run-net-core-web-api-application-in-32-bi