首页 > 解决方案 > 启动新项目或尝试打开现有项目时找不到 .Net v3.5 的系统程序集

问题描述

当我尝试打开以 .Net 3.5 为目标的现有项目或创建一个以它为目标的新项目时,Visual Studio 找不到一些 .Net Framework 程序集: 在此处输入图像描述

如您所见,、 、SystemSystem.Data未找到。System.DrawingSystem.Runtime.SerializationSystem.Xml

我在构建时遇到的错误看起来像

Warning MSB3267 The primary reference "System", which is a framework assembly, could not be resolved in the currently targeted framework. ".NETFramework,Version=v3.5". 
To resolve this problem, either remove the reference "System" or retarget your application to a framework version which contains "System".  

如果我将项目重新定位到 .Net v4.5 之类的东西,那么会找到所有程序集,但我需要它以 v3.5 作为目标进行构建。

我尝试解决的问题:1)我确保在 Windows 功能中启用了 .Net3.5: 在此处输入图像描述

2) 我确保在 Visual Studio 中安装了 3.5 开发工具: 在此处输入图像描述

3)我尝试从微软安装文件手动安装.Net v3.5

到目前为止,这些步骤都没有帮助。我尝试手动搜索这些丢失的 dll,并在 的各种子文件夹中找到它们C:\Windows\Microsoft.NET\Framework,主要是在C:\Windows\Microsoft.NET\Framework\v2.0.50727.

解决此问题的正确方法是什么?如何将 VS 指向程序集?我的设置有问题吗?

软件版本:Visual Studio Community 2019 v16.53、Windows 10 Pro 以及一些新的更新

标签: c#visual-studiowindows-10.net-3.5

解决方案


在四处询问后,我被告知这是 msbuild 中一个古老且已知的错误,有很多可能的解决方法:https ://github.com/microsoft/msbuild/issues/1333

我个人使用了一个自定义FrameworkPathOverridehttps ://github.com/microsoft/msbuild/issues/1333#issuecomment-296346352 ,编辑我已经将这个 XML 剪辑添加到我的作品.csproj中,它就像一个魅力:

<PropertyGroup>
  <FrameworkPathOverride Condition="'$(TargetFramework)' == 'net35'">$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\Client</FrameworkPathOverride>
</PropertyGroup>

之后,卸载/加载项目,我很高兴。


推荐阅读