我正在 Linux 上的 Visual Studio Code 上使用 ASPNET Core 2.0 开发 Web 应用程序。但是我尝试部署应用程序的主机是 Windows Server,唯一可用的目标选项是 .Net Framework 4.6。
所以,当我尝试运行 dotnet publish -o/folder -f net461
时,它显示了我
this error .
是否可以在 linux 上开发一个 aspnet core 应用程序并使用 .Net Framework 将其部署到 windows 上?
错误正文如下:
/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1122,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.1" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/home/maransatto/Projects/FATEC/EraDoConhecimento/web/BDAg.csproj]
最佳答案
有两种场景:ASP.Net Core with .Net framework 和 ASP.Net Core with .Net Core。您不能在 Linux 上使用 .net 框架开发 asp.net 核心,因此您的应用程序的目标可能是“netcoreapp2.0”(假设您下载了最新版本)。您可以仅使用 .net core runtime 2.0 在 Windows 服务器上部署您的应用程序。
你的命令应该是
dotnet publish -c Release -f netcoreapp2.0
您可以部署依赖于框架或自包含的版本。参见 ( https://learn.microsoft.com/en-us/dotnet/core/deploying/index)。
您还需要在带有 IIS 集成的 Windows 上使用 Asp.Net Core 模块。 https://learn.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x
当发布自包含时,您不需要在服务器上安装 .net 核心。
关于linux - VS 代码 + 开发(Linux) + 目标(.net Framework) + 主机(Windows),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46934883/