在分支之间转换时生成错误:您的项目未引用“ .NETFramework,Version = v4.7.2”。构架 [英] Build error while transitioning between branches: Your project is not referencing the ".NETFramework,Version=v4.7.2" framework

查看:556
本文介绍了在分支之间转换时生成错误:您的项目未引用“ .NETFramework,Version = v4.7.2”。构架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用Git,我们有一个针对整个网络框架的解决方案。几天前,我已经开始将解决方案迁移到.net core。不幸的是,出现了一些使我回到master分支的问题(该分支具有完整的.NET框架的代码)。每当我尝试构建应用程序时,都会出现以下错误:

We're using Git and we have a solution which is targeting the full net framework. A couple of days ago, I've started migrating the solution to .net core. Unfortunately, something comes up which made me go back to the master branch (which has the code for the full .NET framework). Whenever I try to build the app, I get the following error:


1> D:\Program Files(x86)\Microsoft Visual
Studio\2017\社区\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5):
错误:您的项目未引用
.NETFramework,Version = v4.7.2框架。在
project.json的框架部分中添加对
.NETFramework,Version = v4.7.2的引用,然后重新运行NuGet恢复。

1>D:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets(186,5): error : Your project is not referencing the ".NETFramework,Version=v4.7.2" framework. Add a reference to ".NETFramework,Version=v4.7.2" in the "frameworks" section of your project.json, and then re-run NuGet restore.

我尝试清理nuget包,运行git reset,但似乎无济于事。

I've tried cleaning up the nuget packages, running a git reset, but nothing seems to help. Any idea on what's going on?

推荐答案

将某些项目从4.6.2升级到4.7.2时,我遇到了类似的问题-这既针对我们针对整个框架的ASP.Net Core解决方案,也针对我们WPF解决方案。

I had a similiar issue when upgrading some projects from 4.6.2 to 4.7.2 - this happened for both our ASP.Net Core solution targetting full framework, and our WPF solution.

最初似乎是随机项目出现此错误,其他具有几乎完全相同的csproj的项目正在构建中,而其他则失败了。消息中的重新运行NuGet恢复也使我走错了道路(其中一些项目甚至没有NuGet参考...)

Initially it seemed to be random projects that had this error, other projects with near exact same csproj were building fine and others were failing. The 're-run NuGet restore' in the message sent me down the wrong path aswell (some of these projects didn't even have NuGet references...)

问题似乎源于包含project.assets.json文件的项目obj文件夹,我不确定何时生成此文件-可能是过去的文物,并且清理项目不会删除此文件。该文件指向以前的框架,以我的情况为例4.6.2-手动删除每个不会生成&的项目的bin / obj文件夹然后重建为我解决了该错误。这也可以解释为什么我出于理智而克隆存储库时,它也可以正常运行。

The issue appears to stem from the projects obj folder containing a project.assets.json file, I'm not sure when this was generated - likely relics from the past, and cleaning the project does not remove this. The file points to the previous framework, in my case 4.6.2 - Manually deleting the bin/obj folders for each project that wouldn't build & then rebuilding resolved this error for me. This would also explain why when I cloned the repo for my sanity, it also built fine.

这篇关于在分支之间转换时生成错误:您的项目未引用“ .NETFramework,Version = v4.7.2”。构架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆