从 Visual Studio 2019 将 ASP.NET Core 3.1 站点发布到 Azure 时出错 [英] Error publishing an ASP.NET Core 3.1 site to Azure from Visual Studio 2019
问题描述
我有一个预先存在的 ASP.NET Core 3.0 应用程序,它已成功部署到 Azure App Service(使用 AspNetCoreModuleV2
模块).将应用程序升级到(今天的版本)ASP.NET Core 3.1 后,应用程序可以在我的本地版本 IIS Express 上正确构建和运行.但是,当我尝试使用(今天的版本)Visual Studio 16.4 发布到 Azure 应用服务时,我收到以下错误:
资产文件C:Projectobjproject.assets.json"没有.NETCoreApp,Version=v3.0"的目标.确保恢复已运行,并且您已在项目的 TargetFrameworks 中包含netcoreapp3.0".
注意事项
- 所有
<PackageReference>
到Microsoft.AspNetCore
、Microsoft.EntityFrameworkCore
和Microsoft.Extensions
> 已更新到3.1.0
- 我已经清理了我的解决方案,甚至删除了我的
obj
文件夹,以确保没有任何挥之不去的引用. - 此错误是由
Microsoft.PackageDependencyResolution.targets
的3.1.100
版本生成的.
我知道 something 仍然挂在 .NET Core 3.0 依赖项上.但目前尚不清楚为什么这只会在部署期间引起问题.Azure 应用服务的还没有为 .NET Core 3.1 做好准备吗?或者这是依赖解析目标的问题?
直接的问题——正如原始问题中指出的那样——与设置 <TargetFramework>
的两个地方有关:
- 项目文件(例如,
csproj
) - 发布配置文件(即
pubxml
)
<TargetFramework>
必须在两个位置更新,并且它们必须完全匹配.否则,发布将无法在 project.assets.json
文件中找到其目标,该文件是基于
构建的>csjproj 文件.
注意:您可能希望 pubxml
文件遵循 <TargetFramework>
设置csproj
文件,但 不是 的情况.
文本编辑器
要通过文本编辑器进行此修改,
- 打开
~/Properties/PublishProfiles
文件夹. - 打开您要编辑的
*.pubxml
. - 将
的值修改为netcoreapp3.1
:
<TargetFramework>netcoreapp3.1</TargetFramework>
Visual Studio 2019
要通过 Visual Studio 2019 IDE 进行此修改,
- 单击Web One Click Publish 工具栏上的齿轮图标(它位于发布图标的右侧).
- 假设目标框架没有设置为
netcoreapp3.1
,点击旁边的编辑图标. - 确保 Target Framework 设置为
netcoreapp3.1
. - 点击保存.
<块引用>
警告:在使用 IDE 时,您可能会在此处遇到问题.编辑配置文件时,您可能会看到项目文件(即 netcoreapp3.1
)中的 new 值已被选中.但是,当您单击 Save 时,它将恢复为 原始 值(例如,在我的情况下为 netcoreapp3.0
).这是因为您实际上并没有更改界面中的值,Visual Studio 错误地认为没有更改 基础 值.如果您临时切换另一个值(例如,Configuration),那么 Visual Studio 将识别出发生了更改,并且 两个 值将在 * 中更新.pubxml
文件.
再次感谢@PanagiotisKanavos 为我指明了正确的方向(请参阅原始线程的评论).
I have a preexisting ASP.NET Core 3.0 application which is successfully deployed to an Azure App Service (using the AspNetCoreModuleV2
module). 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. 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:
Assets file 'C:Projectobjproject.assets.json' doesn't have a target for '.NETCoreApp,Version=v3.0'. Ensure that restore has run and that you have included 'netcoreapp3.0' in the TargetFrameworks for your project.
Notes
- All
<PackageReference>
's toMicrosoft.AspNetCore
,Microsoft.EntityFrameworkCore
, andMicrosoft.Extensions
have been updated to3.1.0
- I have cleaned my solution, and even nuked my
obj
folder to ensure there aren't any lingering references. - This error is being generated from the
3.1.100
version ofMicrosoft.PackageDependencyResolution.targets
.
I get that something is still hanging onto the .NET Core 3.0 dependencies. But it's unclear why that's only causing problems during deployment. Are Azure App Service's not yet ready for .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:
- The project file (e.g.,
csproj
) - The publishing profile (i.e.,
pubxml
)
The <TargetFramework>
must be updated in both locations, and they must match exactly. 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.
Note: You may well expect the
pubxml
file to defer to the<TargetFramework>
set in thecsproj
file, but that is not the case.
Text Editor
To make this modification via a text editor,
- Open the
~/Properties/PublishProfiles
folder. - Open the
*.pubxml
you wish to edit. - Modify the value of
<TargetFramework>
tonetcoreapp3.1
:
<TargetFramework>netcoreapp3.1</TargetFramework>
Visual Studio 2019
To make this modification via the Visual Studio 2019 IDE,
- Click the gear icon on the Web One Click Publish toolbar (it's to the right of the publish icon).
- Assuming the Target Framework is not set to
netcoreapp3.1
, click the edit icon next to it. - Ensure that the Target Framework is set to
netcoreapp3.1
. - Click Save.
Warning: When using the IDE, you may run into a problem here. When editing the profile you'll likely see the new value from your project file (i.e.,
netcoreapp3.1
) already selected. When you click Save, however, it will revert back to the original value (e.g.,netcoreapp3.0
in my case). 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. If you temporarily toggle another value (e.g., Configuration), then Visual Studio will recognize that a change has occurred, and both values will be updated in the*.pubxml
file.
Thank you, again, to @PanagiotisKanavos for pointing me in the right direction (see comments on original thread).
这篇关于从 Visual Studio 2019 将 ASP.NET Core 3.1 站点发布到 Azure 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!