简体   繁体   English

Visual Studio 2010:无法解析目标框架“.NETFramework,Version=v4.0”的 mscorlib

[英]Visual Studio 2010: Could not resolve mscorlib for target framework '.NETFramework,Version=v4.0'

We are currently migrating all our solutions from 2005 to 2010 (that's right, we're skipping 2008.).我们目前正在将我们所有的解决方案从 2005 年迁移到 2010 年(没错,我们跳过了 2008 年。)。 We are also changing our file structure to make some more sense (some common projects would be nested within specific projects etc etc).我们也在改变我们的文件结构以使其更有意义(一些常见的项目将嵌套在特定的项目中等等)。

This all means references need to be changed.这一切都意味着需要更改引用。 Apart from that we are also setting them all to .NET 4.0.除此之外,我们还将它们全部设置为 .NET 4.0。 To accomplish this we've made a temp "GOD" solution with all 117 projects in the same solution.为了实现这一点,我们制作了一个临时的“GOD”解决方案,所有 117 个项目都在同一个解决方案中。

I am doing this with one co-worker and until about 2 hours ago everything was going according to plan.我正在和一位同事一起做这件事,直到大约 2 小时前,一切都在按计划进行。 However we ran into a problem with one of the 117 projects.然而,我们遇到了 117 个项目中的一个问题。 This project refuses to "display" it's references, resources, services, and settings tabs within the Project Properties.该项目拒绝在项目属性中“显示”它的引用、资源、服务和设置选项卡。

I get the following exact message:我收到以下确切消息:

Could not resolve mscorlib for target framework '.NETFramework,Version=v4.0'.无法为目标框架“.NETFramework,Version=v4.0”解析 mscorlib。 This can happen if the target framework is not installed or if the framework moniker is incorrectly formatted.如果未安装目标框架或框架名称格式不正确,就会发生这种情况。

Now this is annoying but it gets worse.现在这很烦人,但情况变得更糟。 My co-worker, when getting the same solution from subversion, CAN actually see and change the references and things.我的同事,当从颠覆中获得相同的解决方案时,实际上可以看到并更改引用和事物。 As a matter of fact, currently the project actually BUILDS on his machine.事实上,目前该项目实际上是在他的机器上构建的。 He committed the changes but I can't build this specific project, or see the references.他提交了更改,但我无法构建此特定项目,也无法查看参考资料。

Which leads me to the simple conclusion, something has to be different on my client which is causing trouble: Suggestions online that I've seen are the following:这使我得出一个简单的结论,我的客户必须有所不同,这会引起麻烦:我在网上看到的建议如下:

  • Multiple .NET4.0 versions installed (this is not the case on my client)安装了多个 .NET4.0 版本(我的客户端不是这种情况)
  • .NET v3.5 is not installed; .NET v3.5未安装; v4.0 is trying to build v3.5 (3.5 is installed on my client) v4.0 正在尝试构建 v3.5(3.5 安装在我的客户端上)
  • The registery key: OnlyUseLatestCLR is set and is screwing things up, (scanned my registry, this key is not present anywhere!)注册表项:OnlyUseLatestCLR 已设置并且正在搞砸,(扫描了我的注册表,此密钥在任何地方都不存在!)

See: http://connect.microsoft.com/VisualStudio/feedback/details/542789/请参阅: http://connect.microsoft.com/VisualStudio/feedback/details/542789/

The only thing I haven't tried yet which I could do is repair .NET 4.0 how ever I highly doubt this is the issue since we have about 100 other projects which I can edit and build just fine.我唯一还没有尝试过但我能做的就是修复 .NET 4.0 我非常怀疑这是个问题,因为我们还有大约 100 个其他项目,我可以很好地编辑和构建它们。 Both C# and VB.NET. C# 和 VB.NET。

It could be that the path to your solution is too long: 解决方案的路径可能太长:

Meaning: 含义:

C:\\MyProject\\Folder\\SubFolder... C:\\ MyProject \\ Folder \\ SubFolder ...

should be Under "256 Character". 应该在“ 256个字符”下。

http://wcfvs.blogspot.com/2011/04/could-not-resolve-mscorlib-for-target.html http://wcfvs.blogspot.com/2011/04/could-not-resolve-mscorlib-for-target.html

I found this thread when I had the same issue but had no reference issues. 当我遇到相同的问题但没有参考问题时,我找到了这个线程。 I found the link above and it solved my problem. 我找到了上面的链接,它解决了我的问题。 Hopefully this will help someone else who comes here with the same problem. 希望这将对遇到同样问题的其他人有所帮助。

Microsoft Visual Basic for Applications Extensibility 5.3 (VBIDE) is the name of the devil!!! Microsoft Visual Basic应用程序可扩展性5.3(VBIDE)是恶魔的名字!!!

Apparently this is a reference which my co-worker had somehow, but i didn't and because of this reference, EVERYTHING died. 显然,这是我的同事提供的参考,但是我没有,由于这个参考,一切都死了。 We discovered this because if you check "Show all files" on the specific project (which is a VB.NET project) you get the sweet References folder, which is normally not there for VB.Net project it's seems. 我们发现此问题是因为,如果您在特定项目(这是一个VB.NET项目)上选中“显示所有文件”,则会得到一个甜美的References文件夹,这似乎对于VB.Net项目通常不存在。 Where the Tab failed us, the folder showed us one reference with a warning. 如果选项卡使我们失败,则文件夹向我们显示了一个带有警告的参考。 Apparently this is something the compiler or VS2010 couldn't tell me but was exactly what was messing it up for us. 显然,这是编译器或VS2010无法告诉我的,但实际上是让我们感到困惑的事情。

So, if you get this error when working on a project, "Show all files" so you get to see the References folder, and find out which reference could be causing your problems! 因此,如果在处理项目时遇到此错误,请“显示所有文件”,以便您可以看到References文件夹,并找出可能导致问题的参考!

I'm glad it found this though, after more then 3 hours!! 我很高兴在3个多小时后发现了它!! >.< >。<

I was getting this error this morning. 我今天早上遇到这个错误。 I just did the following: 我只是做了以下事情:

  1. Rebuild the Project 重建项目
  2. Closed Visual Studio 封闭的Visual Studio
  3. Re-opened Visual Studio 重新打开Visual Studio

and the error was gone. 错误消失了。

我参与了我的项目,保存了工作并关闭了Visual Studio2010。再次打开进行工作时出现此错误,我只是关闭了Visual Studio,然后再次复制了保存项目的文件,然后将其粘贴到了其他地方(在我桌面上的文件中) ),然后我再次使用VS2010打开了该项目,该项目正在运行。

I had the same issue with a (web) service reference in my project. 我的项目中的(Web)服务引用也存在相同的问题。 Both " Update service Reference " and " Configure Service Reference " did not work anymore. 更新服务参考 ”和“ 配置服务参考 ”都不再起作用。

Well lets just throw the (web) service reference away and create it again. 好吧,我们只需要丢弃(web)服务引用并重新创建即可。 No go! 不行! Same error message. 同样的错误信息。

Solution: Edit the project file and remove everything which has to do with service references. 解决方案:编辑项目文件,并删除所有与服务引用有关的内容。

Instructions: 说明:

  • Go to the Solution Explorer and right click on the project name and select "Unload project". 转到解决方案资源管理器,然后右键单击项目名称,然后选择“卸载项目”。
  • Go to the Solution Explorer and right click on the project name and select "Edit YourProjectName.proj" 转到解决方案资源管理器,然后右键单击项目名称,然后选择“编辑YourProjectName.proj”
  • Remove every element with has something to do with your (web) service references. 删除与(Web)服务引用有关的每个元素。 (Typically it contains text "service references") (通常包含文本“服务引用”)
  • Go to the Solution Explorer and right click on the project name and select "Reload project". 转到解决方案资源管理器,然后右键单击项目名称,然后选择“重新加载项目”。
  • Now add your (web) service references again. 现在,再次添加您的(Web)服务引用。

Problem solved (Well it was in my case). 问题解决了(对我而言)。

My guess of what could have happened: I changed a class somewhere in my web service. 我对可能发生的事情的猜测:我在Web服务中的某个地方更改了一个类。 The interface was not changed and Visual Studio somehow does not see the change(s). 界面未更改,Visual Studio以某种方式看不到更改。 The (cached?) configuration does not match anymore and configuring/rebuilding/deleting the (web) service fails. (已缓存?)配置不再匹配,并且配置/重建/删除(Web)服务失败。

I had the same issue and after try most of the above, including reinstalling .Net 4.0 and rebooting still didnt go away. 我遇到了同样的问题,在尝试了上述大多数方法后,包括重新安装.Net 4.0和重新启动仍然没有消失。

Eventually solved it by moving my project tree lower down. 最终通过将我的项目树向下移动来解决了。 ie. 即。 closer to the root of the drive. 更接近驱动器的根。 Turns out the directory and filenames were too long and I believe the references were being truncated and therefore couldnt resolve. 原来目录和文件名太长,我认为引用被截断了,因此无法解析。

Problem came right immediately. 问题马上就解决了。

I had this problem today and the solution was to manually edit the Resources.resx file manually. 我今天遇到了这个问题,解决方案是手动编辑Resources.resx文件。

My Resources.resx file looked like this: 我的Resources.resx文件如下所示:

  <data name="SomeString" xml:space="preserve">
    <value>I am a string</value>
  </data>
  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  <data name="MyLogo" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\MyLogo.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>
  <data name="Open" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\Open.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>

Turned out that Visual Studio didn't like the two <data> elements after the <assembly> element, which is strange considering the fact that Visual Studio added them there itself. 原来Visual Studio不喜欢在<assembly> <data>元素之后的两个<data>元素,考虑到Visual Studio本身将它们添加到其中的事实,这很奇怪。 My problem was solved after I moved them before the <assembly> element: 在将它们移动到<assembly>元素之前后,我的问题已解决:

  <data name="SomeString" xml:space="preserve">
    <value>I am a string</value>
  </data>
  <data name="MyLogo" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\MyLogo.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>
  <data name="Open" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>..\Resources\Open.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>
  <assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

Happened to me in the Resource Editor. 发生在资源编辑器中。

Cause: I was importing some .Targets file, which defined a property called AppConfigFile, which probably over-wrote some internal property of the same name: 原因:我正在导入一些.Targets文件,该文件定义了一个名为AppConfigFile的属性,该文件可能会改写一些同名的内部属性:

<PropertyGroup>
  <AppConfigFile>...</AppConfigFile>
</PropertyGroup>

Fix: Renamed property to some other name, and the problem went away. 修复:将属性重命名为其他名称,问题消失了。

I had this problem in Visual Studio 2013 when going from .NET 4.5 to .NET 4.6.2. 从.NET 4.5到.NET 4.6.2时,我在Visual Studio 2013中遇到此问题。 The problem project was a website project. 问题项目是一个网站项目。

Visual Studio automatically runs some tool which generates Reference.svcmap. Visual Studio自动运行一些生成Reference.svcmap的工具。 The Reference.cs starts with: Reference.cs开头为:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

Just picking the new .NET version caused Visual Studio to clean out the generated files and not fill the contents back. 只是选择新的.NET版本,导致Visual Studio清除生成的文件,而不回填内容。 I tried all the solutions above but none worked. 我尝试了上述所有解决方案,但没有一个起作用。 Eventually I picked .NET 4.5.1 followed by .NET 4.6.2 and the tool did run. 最终,我选择了.NET 4.5.1,然后选择了.NET 4.6.2,该工具确实运行了。 The difference in the files was only the version number of the tool which was in a comment, so I could have recovered the files from GIT. 文件中的区别只是注释中的工具的版本号,因此我可以从GIT中恢复文件。

I had the same issue when the source directory was read only. 源目录为只读时,我遇到了同样的问题。 If I sync my workspace with our version control server (Perforce), it will make all of the directories read only by default unless I select that I am checking out the directory for editing. 如果我将我的工作空间与版本控制服务器(Perforce)同步,则默认情况下它将使所有目录均为只读,除非我选择退出要编辑的目录。 Sometimes I am lazy and don't do this since I am the only person working on some of these projects at any point in time. 有时我很懒惰,不这样做,因为在任何时候我都是唯一从事某些项目的人。 But this error goes away clear the read only flag. 但是此错误消失了,清除了只读标志。

我发生的事情是我对项目的所有引用都丢失了,因此我不得不再次插入它们。

for me, just setting Target Framework 4.0 resolved my problem. 对我来说,仅设置Target Framework 4.0即可解决我的问题。 Sometimes the target framework is clear somehow. 有时目标框架以某种方式很明确。 That might cause problem. 那可能会引起问题。

I ran in to this problem today, and it proved to be caused of too long filenames in the project. 我今天遇到了这个问题,事实证明这是由于项目中文件名过长引起的。

This, in turn, was caused by some service references. 反过来,这是由某些服务引用引起的。 When a service reference is imported or updated, visual studio generates .datasource files, where the filename is the fully qualified name. 导入或更新服务引用时,Visual Studio会生成.datasource文件,其中文件名是标准名称。 This means really long names in some instances. 这意味着在某些情况下名称很长。

By googling around, I found hints that it was safe to delete these files. 通过四处搜寻,我发现提示删除这些文件是安全的。 Check this or this out. 检查这个这个

Deleting these .datasource files removed the problem. 删除这些.datasource文件可解决此问题。

I was migrating a vb.net project to VS 2015. I also had the same issue. 我正在将vb.net项目迁移到VS2015。我也遇到了同样的问题。 The problem is not with the .Net framework, since I was able to create a new Project targeting the specific Framework Versions and it succeeded. .Net框架不是问题所在,因为我能够创建一个针对特定框架版本的新项目,并且成功。

In my case, the project was referencing FPSpreadADO and some other similar libraries. 就我而言,该项目引用了FPSpreadADO和其他一些类似的库。 It worked fine once I removed those references. 一旦我删除了这些引用,它就可以正常工作。

I had a similar error in XamarinForms PCL project. XamarinForms PCL项目中出现了类似的错误。
I found out that the error was about a reference of the project. 我发现该错误与该项目的参考有关。 I updated the xamarin.forms to the last version and for some reasons NuGet was not able to remove all references of the previous version from the project file (xml). 我将xamarin.forms更新为最新版本,由于某些原因,NuGet无法从项目文件(xml)中删除先前版本的所有引用。
So, simply I deleted the following line from the project file and it worked! 因此,只需将项目文件中的以下行删除即可。

<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.1.114\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.1.114\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />

Hope it helps someone... 希望它可以帮助某人...

I got this error too. 我也收到此错误。 ("Could not resolve mscorlib for target framework '.NetFramework 4.5.1'. This can happen if the target framework is not installed or if the framework moniker is incorrectly formatted."). (“无法解析目标框架'.NetFramework 4.5.1'的mscorlib。如果未安装目标框架或框架标记的格式错误,则可能会发生这种情况。”)。

This happened when I changed the framework from 3.5 to 4.5.1 on a VB 2013 project. 当我在VB 2013项目中将框架从3.5更改为4.5.1时,发生了这种情况。 The solution was to remove all the references on the .vbproj file: all the references labeled Reference and COMReference groups. 解决方案是删除.vbproj文件上的所有引用:所有标记为Reference和COMReference组的引用。

Of course just after doing this all kind of other errors appeared on the project. 当然,这样做之后,所有其他错误也会出现在项目中。

Then I started to copy them back, one by one in the same place, copying from a back-up in order to identify which between them were the problematic ones (I copied the ones related with the new errors I got in order to fix them), refreshing the project each time until the affected window visualized properly. 然后,我开始在同一位置逐个复制它们,从备份中复制,以识别它们之间哪个是有问题的(我复制了与新错误有关的错误以修复它们。 ),每次刷新项目,直到受影响的窗口正确可视化为止。

It resulted they were some customized libraries references which created this problem. 结果导致它们是一些自定义的库引用,从而导致了此问题。 I hope this could help someone. 我希望这可以帮助某人。 Cheers! 干杯!

A Developer. 开发人员。

I ran into this issue today in Visual Studio 2017 on a project that I had apparently started out as a Universal Windows Platform application but ultimately settled on a Windows Forms desktop application. 我今天在Visual Studio 2017中遇到了一个问题,该项目显然是我最初作为通用Windows平台应用程序开始的,但最终决定使用Windows Forms桌面应用程序。

Somehow, either through a branching mistake or commit problem in source control, some of the obsolete/discarded UWP XAML files, along with a "project.json" file wound up back in my project folder. 无论如何,由于分支错误或源代码管理中的提交问题,一些过时/废弃的UWP XAML文件以及“ project.json”文件都重新缠绕在我的项目文件夹中。 VS would no longer build or launch my Windows Forms app with a similar error as reported by others above (eg, "Could not resolve mscorlib for target framework '.NETFramework,Version=v4.7'"). VS将不再以与上面其他人所报告的错误类似的错误构建或启动Windows Forms应用程序(例如,“无法为目标框架'.NETFramework,Version = v4.7'解析mscorlib”)。

After deleting all of the obsolete UWP junk (including "project.json", all the XAML files, and any other related nonsense) out of the project folder and reloading the solution, the errors went away and the project both built and launched successfully. 从项目文件夹中删除所有过时的UWP垃圾(包括“ project.json”,所有XAML文件以及任何其他相关的废话)并重新加载解决方案之后,错误消失了,并且项目成功构建并启动。

Hope this helps. 希望这可以帮助。

In most case it happened because of missing reference. 在大多数情况下,它是由于缺少参考而发生的。
In solution explorer --> Reference -- > you can see the missing reference (in yellow) just add the reference you will be fine. 在解决方案资源管理器->参考->中,您可以看到缺少的参考(黄色),只需添加参考即可。

Ran into this today. 今天就碰到这个。

Deleted bin & obj folders. 删除bin和obj文件夹。

Reopened Visual Studio and it suddenly worked. 重新打开Visual Studio,它突然工作了。

Check that the target framework in the project properties is set correctly - by default this is ".Net Framework 4.0 Client" - it may be that you require ".Net Framework 4.0" 检查项目属性中的目标框架是否设置正确-默认情况下为“ .Net Framework 4.0 Client”-可能是您需要“ .Net Framework 4.0”

see this thread that looks like the same issue 看到看起来像同一问题的线程

you may also want to review this article which relates to debugging an issue with the same symptom using reflector 您可能还需要阅读这篇文章该文章与使用反射器调试具有相同症状的问题有关

我的解决方案是从NuGet软件包管理器中下载并安装Microsoft.NETCore.UniversalWindowsPlatform

Had this prblem with Visual Studio 2019 Preview (v. 16). Visual Studio 2019 Preview (v. 16) 有这个问题。

Solved it by changing the project's target framework from .NET Framework v. 4.7.2 to 4.6 , then back to 4.7.2 .通过将项目的目标框架从 .NET Framework v. 4.7.2更改为4.6 ,然后返回到4.7.2来解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法解析目标框架“.NETFramework,Version=v4.6.1”的 mscorlib - Could not resolve mscorlib for target framework '.NETFramework,Version=v4.6.1' Visual Studio 2015:无法解析目标框架的 mscorlib - Visual Studio 2015: Could not resolve mscorlib for target framework 发出调试代码当前目标框架.NETFRAMEWORK,版本= v4.0 - Got issue debugging code The currently targeted framework .NETFRAMEWORK, Version =v4.0 “ .NETFramework,Version = v4.0,Profile = Mono”问题vb.net,c# - “.NETFramework,Version=v4.0,Profile=Mono” issue vb.net, c# 哪些文件存储在 Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 中? - Which files are stored in Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0? 项目<PROJECT NAME>不是最新的。 缺少输入文件 &#39;netframework,version=v4.0,profile=client.assemblyattributes.cs - Project <PROJECT NAME> is not up to date. Missing input file 'netframework,version=v4.0,profile=client.assemblyattributes.cs 无法在多个项目上更改目标框架从v4.0到V4.5或4.5.1 - Cannot change Target Framework on Several Projects From v4.0 to V4.5 or 4.5.1 将目标框架从v4.0更改为v3.5后,找不到命名空间 - Namespace cannot be found after changing target framework from v4.0 to v3.5 在 Visual Studio 2010 中引用 mscorlib - Referencing mscorlib in Visual Studio 2010 Visual Studio目标框架不会更改为4.0 - Visual Studio target framework not changing to 4.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM