简体   繁体   English

从 Visual Studio 2019 将 ASP.NET Core 3.1 站点发布到 Azure 时出错

[英]Error publishing an ASP.NET Core 3.1 site to Azure from Visual Studio 2019

I have a preexisting ASP.NET Core 3.0 application which is successfully deployed to an Azure App Service (using the AspNetCoreModuleV2 module).我有一个预先存在的ASP.NET Core 3.0应用程序,它已成功部署到Azure 应用服务(使用AspNetCoreModuleV2模块)。 After upgrading the app to (today's release of) ASP.NET Core 3.1 , the application builds and runs correctly on my local version of IIS Express .将应用程序升级到(今天的版本) ASP.NET Core 3.1后,应用程序可以在我的本地版本的IIS Express上正确构建和运行。 When I attempt to publish to the Azure App Service using (today's release of) Visual Studio 16.4 , however, I receive the following error:但是,当我尝试使用(今天的版本) Visual Studio 16.4发布到 Azure App Service 时,我收到以下错误:

Assets file 'C:\Project\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0'.资产文件“C:\Project\obj\project.assets.json”没有“.NETCoreApp,Version=v3.0”的目标。 Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project.确保恢复已运行,并且您已在项目的 TargetFrameworks 中包含“netcoreapp3.0”。

Notes笔记

  • My csproj file's <TargetFramework> is correctly set to netcoreapp3.1 .我的csproj文件的<TargetFramework>正确设置为netcoreapp3.1
  • All <PackageReference> 's to Microsoft.AspNetCore , Microsoft.EntityFrameworkCore , and Microsoft.Extensions have been updated to 3.1.0所有<PackageReference>Microsoft.AspNetCoreMicrosoft.EntityFrameworkCoreMicrosoft.Extensions已更新到3.1.0
  • I have cleaned my solution, and even nuked my obj folder to ensure there aren't any lingering references.我已经清理了我的解决方案,甚至删除了我的obj文件夹以确保没有任何挥之不去的引用。
  • This error is being generated from the 3.1.100 version of Microsoft.PackageDependencyResolution.targets .此错误是从3.1.100版本的Microsoft.PackageDependencyResolution.targets生成的。

I get that something is still hanging onto the .NET Core 3.0 dependencies.我知道有些东西仍然挂在.NET Core 3.0依赖项上。 But it's unclear why that's only causing problems during deployment .但目前尚不清楚为什么这只会在部署期间引起问题。 Is Azure App Service not yet ready for .NET Core 3.1 ? Azure App Service是否还没有为.NET Core 3.1做好准备? Or is this an issue with the dependency resolution targets?或者这是依赖解决目标的问题?

The immediate issue—as identified in the original question—has to do with there being two places where <TargetFramework> is set:直接问题(如原始问题中所述)与设置<TargetFramework>两个位置有关:

  1. The project file (eg, csproj )项目文件(例如csproj
  2. The publishing profile (ie, pubxml )发布配置文件(即pubxml

The <TargetFramework> must be updated in both locations, and they must match exactly . <TargetFramework>必须在两个位置更新,并且它们必须完全匹配。 Otherwise, the publishing won't be able to find its targets in the project.assets.json file, which is built based on the <TargetFramework> in the csjproj file.否则,发布将无法在project.assets.json文件中找到其目标,该文件是基于csjproj文件中的<TargetFramework>构建的。

Note: You may well expect the pubxml file to defer to the <TargetFramework> set in the csproj file, but that is not the case.注意:您可能希望pubxml文件遵循csproj文件中设置的<TargetFramework> ,但事实并非如此。

Text Editor文本编辑器

To make this modification via a text editor,要通过文本编辑器进行此修改,

  1. Open the ~/Properties/PublishProfiles folder.打开~/Properties/PublishProfiles文件夹。
  2. Open the *.pubxml you wish to edit.打开您要编辑的*.pubxml
  3. Modify the value of <TargetFramework> to netcoreapp3.1 :<TargetFramework>的值修改为netcoreapp3.1
<TargetFramework>netcoreapp3.1</TargetFramework>

Visual Studio 2019视觉工作室 2019

To make this modification via the Visual Studio 2019 IDE,要通过Visual Studio 2019 IDE 进行此修改,

  1. Click the gear icon on the Web One Click Publish toolbar (it's to the right of the publish icon).单击Web One Click Publish工具栏上的齿轮图标 (它位于发布图标的右侧)。
  2. Assuming the Target Framework is not set to netcoreapp3.1 , click the edit icon next to it.假设Target Framework设置为netcoreapp3.1 ,请单击它旁边的编辑图标。
  3. Ensure that the Target Framework is set to netcoreapp3.1 .确保目标框架设置为netcoreapp3.1
  4. Click Save .单击保存

Warning: When using the IDE, you may run into a problem here.警告:使用 IDE 时,您可能会在此处遇到问题。 When editing the profile you'll likely see the new value from your project file (ie, netcoreapp3.1 ) already selected.编辑配置文件时,您可能会看到项目文件(即netcoreapp3.1 )中的值已被选中。 When you click Save , however, it will revert back to the original value (eg, netcoreapp3.0 in my case).但是,当您单击Save时,它​​将恢复为原始值(例如,在我的情况下为netcoreapp3.0 )。 This is because you didn't actually change the value in the interface, which Visual Studio mistakes for there not being a change to the underlying values.这是因为您实际上并没有更改界面中的值,Visual Studio 将其误认为基础值没有更改。 If you temporarily toggle another value (eg, Configuration ), then Visual Studio will recognize that a change has occurred, and both values will be updated in the *.pubxml file.如果您临时切换另一个值(例如Configuration ),则 Visual Studio 将识别出发生了更改,并且两个值都将在*.pubxml文件中更新。

Acknowledgements致谢

Thank you, again, to @PanagiotisKanavos for pointing me in the right direction ( see comments on original thread ).再次感谢@PanagiotisKanavos为我指明了正确的方向( 请参阅原始线程的评论)。

Open Project folder;打开项目文件夹;

  • Navigate to folder Properties>>PublishProfiles导航到文件夹属性>>发布配置文件
  • Open file FolderProfile.pubxml then change version 3.0 to 3.1打开文件 FolderProfile.pubxml 然后将版本3.0更改为3.1

    netcoreapp3.1 netcoreapp3.1

  • Finally, rebuild your application before publishing最后,在发布之前重建您的应用程序

I got this error from a fresh new net5.0 project in VS2019 (ASP.NET Core Web Application template) when using the VS web-publisher.使用 VS web-publisher 时,我从 VS2019(ASP.NET Core Web 应用程序模板)中的一个全新的 net5.0 项目中收到此错误。 The solution is as follows:解决方法如下:

  1. Open file: {project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml打开文件: {project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml

  2. Add the following line inside the <PropertyGroup> element:<PropertyGroup>元素内添加以下行:

    <TargetFramework>net5.0</TargetFramework>

The element was missing entirely - great work MS该元素完全丢失了-伟大的工作MS

change改变

<PackageReferenceInclude="Microsoft.AspNetCore"Version="2.2.0" />
 to 
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />

works for me.为我工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果不手动停止应用程序,则无法将 ASP.NET Core 应用程序从 Visual Studio 发布到 Azure - Publishing ASP.NET Core app from Visual Studio to Azure does not work without manually halting the app 如何使用 Visual Studio 2019 在 Docker 容器中运行 ASP.NET Core 3.1 项目? - How to run an ASP.NET Core 3.1 project in a Docker container with Visual Studio 2019? 通过Visual Studio将ASP.NET Web API发布到Azure时出错 - Error when publishing ASP.NET Web API to Azure over Visual Studio 使用Visual Studio 2017在Azure应用服务中发布ASP.NET应用程序后获取HTTP错误404 - Getting HTTP ERROR 404 after publishing ASP.NET application in Azure App Service with Visual Studio 2017 更新 Visual Studio 2019 删除了 .NET Core 3.1 SDK - Updating Visual Studio 2019 removed .NET Core 3.1 SDK Visual Studio 2019 在哪里可以找到 .net core 3.1 的 WebAssembly 模板 - Visual Studio 2019 where to find WebAssembly template for .net core 3.1 Visual Studio 2019 16.3.6 ASP.NET 内核 Web 应用项目模板确实允许 asp.net 内核版本选择 - Visual Studio 2019 16.3.6 ASP.NET Core Web Application project template does allow asp.net core version selection Visual Studio 2019 中缺少 ASP.NET 核心 Web 应用程序模板和所有 ASP.Net 核心模板 - Missing ASP.NET Core Web Application Template and all ASP.Net Core Templates in Visual Studio 2019 Visual Studio 2019 推出 .net Framework 4.6.2 网站作为 ASP.NET 核心 - Visual Studio 2019 launches .net Framework 4.6.2 website as ASP.NET Core 如何在 cshtml ASP.NET 内核中调试 JavaScript 脚本(使用 Chrome 浏览器或在 Visual Studio 2019 中)? - How to debug JavaScript script in cshtml ASP.NET core ( by using Chrome browser or in Visual Studio 2019)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM