[英]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”。
csproj
file's <TargetFramework>
is correctly set to netcoreapp3.1
.csproj
文件的<TargetFramework>
正确设置为netcoreapp3.1
。<PackageReference>
's to Microsoft.AspNetCore
, Microsoft.EntityFrameworkCore
, and Microsoft.Extensions
have been updated to 3.1.0
<PackageReference>
的Microsoft.AspNetCore
、 Microsoft.EntityFrameworkCore
和Microsoft.Extensions
已更新到3.1.0
obj
folder to ensure there aren't any lingering references.obj
文件夹以确保没有任何挥之不去的引用。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>
的两个位置有关:
csproj
)csproj
)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 thecsproj
file, but that is not the case.注意:您可能希望
pubxml
文件遵循csproj
文件中设置的<TargetFramework>
,但事实并非如此。
To make this modification via a text editor,要通过文本编辑器进行此修改,
~/Properties/PublishProfiles
folder.~/Properties/PublishProfiles
文件夹。*.pubxml
you wish to edit.*.pubxml
。<TargetFramework>
to netcoreapp3.1
:<TargetFramework>
的值修改为netcoreapp3.1
:<TargetFramework>netcoreapp3.1</TargetFramework>
To make this modification via the Visual Studio 2019 IDE,要通过Visual Studio 2019 IDE 进行此修改,
netcoreapp3.1
, click the edit icon next to it.netcoreapp3.1
,请单击它旁边的编辑图标。netcoreapp3.1
.netcoreapp3.1
。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
文件中更新。
Thank you, again, to @PanagiotisKanavos for pointing me in the right direction ( see comments on original thread ).再次感谢@PanagiotisKanavos为我指明了正确的方向( 请参阅原始线程的评论)。
Open Project folder;打开项目文件夹;
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:
解决方法如下:
Open file: {project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml
打开文件:
{project}\Properties\PublishProfiles\{project} - Web Deploy.pubxml
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.