更改目标框架后,ASP.NET Core MVC应用程序无法发布

问题描述:

我有一个目标框架为.NET Core 2.0的MVC Core应用程序.它完美地构建,运行和发布.然后,我安装了Core SDK 2.1,并将目标框架升级为.NET Core 2.1.现在该应用仍然可以正常运行,但是当我尝试发布它时,出现以下错误:

I have an MVC Core application where the target framework was .NET Core 2.0. It built, ran, and published perfectly. Then I installed the Core SDK 2.1 and upgraded the target framework to .NET Core 2.1. Now the app still builds fine, but when I try and publish it, I get the following error:

资产文件 'C:\ Projects \ QuickDrive \ Code \ QuickDrive.Mvc \ obj \ project.assets.json' 没有".NETCoreApp,Version = v2.0"的目标.确保这件事 恢复已运行,并且您已在其中包含"netcoreapp2.0" 您项目的TargetFrameworks.

Assets file 'C:\Projects\QuickDrive\Code\QuickDrive.Mvc\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project.

我尝试删除project.assets.json,但是发布仍然失败.这有什么问题,我该怎么做才能解决并发布我的应用程序?将目标框架设置为2.1后,为什么VS会寻找'.NETCoreApp,Version = v2.0'的目标"?

I have tried deleting project.assets.json but the publish still fails. What is wrong here, and what can I do to resolve this and get my app published? Why is VS looking for "a target for '.NETCoreApp,Version=v2.0'" when I've set the target framework to 2.1?

我正在使用VS 2017 v15.6.6,并且还尝试了经常推荐的dotnet restore.

I am using VS 2017 v15.6.6 and have also tried an often recommended dotnet restore.

这不能解释错误的原因,即使这个问题看起来不那么受欢迎,我还是发布了解决我问题的方法,以防其他人遇到问题同样的事情,同样的解决方案适用于他们.

This doesn't explain the cause of the error, and even though this question seems so disliked, I'm posting what solved my problem in case anyone else experiences the same thing, and the same solution works for them.

简单但庞大的VS2017从v15.6.6升级到v15.7.3解决了该问题.

A simple but huge VS2017 upgrade from v15.6.6 to v15.7.3 solved the problem.