如何在 4.5 .net framework 版本中构建 web api?
How to build web api in 4.5 .net framework version?
我正在尝试构建可以使用 4.5 .net 框架托管环境的 WebApi 应用程序。
我正在使用 Visual Studio 2017(15.4.4 版本),使用 Web Api 核心库创建了空的 Web 应用程序项目。默认情况下,它是为 4.6 .net 框架创建的。
我将项目的目标框架更改为 4.5,删除并重新安装了所有包(它们现在都在 packages.config 中显示为 targetFramework="net45")。
部署到只有 4.5 .net 框架的环境时,编译失败并出现以下错误:
Compilation Error Description: An error occurred during the
compilation of a resource required to service this request. Please
review the following specific error details and modify your source
code appropriately.
Compiler Error Message: The compiler failed with error code
-2146232576.
Show Detailed Compiler Output:
c:\windows\system32\inetsrv>F:\myWebApiApp\bin\roslyn\csc.exe
/t:library /utf8output /nostdlib+
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl3\fb9d2cbc[=11=]44d876_ee54d201\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl3\b709b96ccb112e8_3b95d301\myWebApiAppSvc.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl3\ae5ab688[=11=]9d8143_af3ad001\System.Net.Http.Formatting.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl3\fa0decfa[=11=]523e3f_5aafcf01\Newtonsoft.Json.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl3\f7a56ccd[=11=]3da769_af3ad001\System.Web.Http.WebHost.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll"
/R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\assembly\dl396b4ac[=11=]aba84a_af3ad001\System.Web.Http.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll"
/R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll"
/out:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary
ASP.NET Files\root012382\a302a9b2\App_global.asax.ne6nua60.dll"
/debug- /optimize+ /warnaserror- /w:4 /nowarn:1659;1699;1701;612;618
/langversion:6 /nowarn:1659;1699;1701
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\App_global.asax.ne6nua60.0.cs"
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET
Files\root012382\a302a9b2\App_global.asax.ne6nua60.1.cs"
Version Information: Microsoft .NET Framework Version:4.0.30319;
ASP.NET Version:4.0.30319.36415
在事件查看器中显示:
.NET Runtime version : 4.0.30319.36415 - This application could not be
started.This application requires one of the following versions of the
.NET Framework: .NETFramework,Version=v4.6
Do you want to install this .NET Framework version now?
我错过了什么吗?我如何才能找出究竟取决于 4.6 的是什么?也许有更简单的方法在 4.5 .net 框架中创建 WebApi 应用程序?
非常感谢任何帮助!
您只需在创建项目时指定所需的 .net Framework 版本即可。
我正在尝试构建可以使用 4.5 .net 框架托管环境的 WebApi 应用程序。
我正在使用 Visual Studio 2017(15.4.4 版本),使用 Web Api 核心库创建了空的 Web 应用程序项目。默认情况下,它是为 4.6 .net 框架创建的。
我将项目的目标框架更改为 4.5,删除并重新安装了所有包(它们现在都在 packages.config 中显示为 targetFramework="net45")。
部署到只有 4.5 .net 框架的环境时,编译失败并出现以下错误:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: The compiler failed with error code -2146232576.
Show Detailed Compiler Output:
c:\windows\system32\inetsrv>F:\myWebApiApp\bin\roslyn\csc.exe /t:library /utf8output /nostdlib+ /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl3\fb9d2cbc[=11=]44d876_ee54d201\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activities\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activities.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IdentityModel\v4.0_4.0.0.0__b77a5c561934e089\System.IdentityModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.Serialization\v4.0_4.0.0.0__b77a5c561934e089\System.Runtime.Serialization.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.WorkflowServices\v4.0_4.0.0.0__31bf3856ad364e35\System.WorkflowServices.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Activation\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Activation.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl3\b709b96ccb112e8_3b95d301\myWebApiAppSvc.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel.Web\v4.0_4.0.0.0__31bf3856ad364e35\System.ServiceModel.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.DynamicData\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.DynamicData.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl3\ae5ab688[=11=]9d8143_af3ad001\System.Net.Http.Formatting.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Services\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.Services.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ServiceModel\v4.0_4.0.0.0__b77a5c561934e089\System.ServiceModel.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.EnterpriseServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.EnterpriseServices.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl3\fa0decfa[=11=]523e3f_5aafcf01\Newtonsoft.Json.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\v4.0_4.0.0.0__31bf3856ad364e35\System.ComponentModel.DataAnnotations.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl3\f7a56ccd[=11=]3da769_af3ad001\System.Web.Http.WebHost.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.ApplicationServices\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.ApplicationServices.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\assembly\dl396b4ac[=11=]aba84a_af3ad001\System.Web.Http.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.dll" /out:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\App_global.asax.ne6nua60.dll" /debug- /optimize+ /warnaserror- /w:4 /nowarn:1659;1699;1701;612;618 /langversion:6 /nowarn:1659;1699;1701 "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\App_global.asax.ne6nua60.0.cs" "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root012382\a302a9b2\App_global.asax.ne6nua60.1.cs"
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.36415
在事件查看器中显示:
.NET Runtime version : 4.0.30319.36415 - This application could not be started.This application requires one of the following versions of the .NET Framework: .NETFramework,Version=v4.6
Do you want to install this .NET Framework version now?
我错过了什么吗?我如何才能找出究竟取决于 4.6 的是什么?也许有更简单的方法在 4.5 .net 框架中创建 WebApi 应用程序?
非常感谢任何帮助!
您只需在创建项目时指定所需的 .net Framework 版本即可。