[备忘]处理错误:Your project does not reference ".NETFramework,Version=v4.5" framework. Add a reference to ".NETFramework,Version=v4.5" in the "TargetFrameworks" ...
错误信息:
Your project does not reference ".NETFramework,Version=v4.5" framework. Add a reference to ".NETFramework,Version=v4.5" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
其中一种可能是同一个项目目录,被 .NET Framework 和 .NET Core 两个不同的解决方案引用,导致 obj 内的信息混乱。
解决方案一: 不要同时打开两个具有共享项目文件夹的解决方案,并且注意切换的时候删除 obj 和 bin 文件夹。
解决方案二:添加以下代码到 .NET Framework 的项目文件(.csproj)中:
<Project>
...
<PropertyGroup>
<BaseOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/bin</BaseOutputPath>
<BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/obj</BaseIntermediateOutputPath>
</PropertyGroup>
...
</Project>
I experienced similar issue, but with
v4.7.2
. Namely, I kept getting build log message like this:
error : Your project does not reference ".NETFramework,Version=v4.7.2" framework. Add a reference to ".NETFramework,Version=v4.7.2" in the "TargetFrameworks" property of your project file and then re-run NuGet restore.
Despite the fact that it looked similar, none of the above proposed steps worked for me. I kept seeing this message after each build. Nothing seemed to be able to help.
In fact, the problem was related to that, due to migration, I had to put two projects in one folder of code. One of them was targeted at .Net Core, another at .Net Framework, both referenced same .Net Standard libraries. Apparently, they share the same
obj
folder where Core projects putproject.assets.json
file. Actually, exactly this file interferres with the Framework project preventing its normal build. Seems even if you performed Migrate from packages.config to PackageReference... which was recommended as one of possible solution.You can try to fix the issue by putting the following snippet into your Framework project file:
<Project> ... <PropertyGroup> <BaseOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/bin</BaseOutputPath> <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/out/$(MSBuildProjectName)/obj</BaseIntermediateOutputPath> </PropertyGroup> ... </Project>
It immediately worked for me, it was only later when I attentively read why we need it and why it works. I unexpectedly found it in part 2 of Migrating a Sample WPF App to .NET Core 3 under Making sure the .NET Framework project still builds section.
BaseOutputPath
andBaseIntermediateOutputPath
msbuild variables can be found there, not sure if they are documented well anywhere.
转载请注明出处和作者,谢谢!
作者:JeffreySu / QQ:498977166
博客:http://szw.cnblogs.com/
Senparc官方教程《微信开发深度解析:微信公众号、小程序高效开发秘籍》,耗时2年精心打造的微信开发权威教程,点击这里,购买正版!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· C#/.NET/.NET Core技术前沿周刊 | 第 29 期(2025年3.1-3.9)
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
2011-02-08 [原创]Senparc Google Sitemap 升级至v1.5
2011-02-08 [原创]Senparc Google Sitemap 提供Sitemap开放下载服务
2011-02-08 [原创]Senparc Google Sitemap 的Callback使用教程