在安装框架4.5时,目标是。net Framework 4。

时间:2022-02-13 16:47:19

I have VS2010 and VS2012 installed on my computer and had the .NET Framework 4.0 which I then upgraded to .NET Framework 4.5. However, I am still developing apps that need to work on .NET Framework 4.0. The project says that it is targeting .NET Framework 4 (Client Profile) the assemblies even point to .NET Framework 4.0 folder under Referenced Assemblies. The problem comes when I move this application to a machine that only has 4.0 it won't start and come up with errors the immediate problem being an exception resulting from WindowState={Binding WindowState} which you can't do in 4.0 but you can in 4.5. I need this to throw the exception on my development box, why doesn't it? My assumption is that despite my best efforts is that it uses the 4.5 dlls if they exist. How can I make it really use 4.0 without uninstall 4.5?

我在我的电脑上安装了VS2010和VS2012,并拥有。net Framework 4.0,然后升级到。net Framework 4.5。然而,我仍然在开发需要在。net Framework 4.0中工作的应用程序。该项目说,它的目标是。net Framework 4(客户端配置文件),甚至在被引用的程序集下指向。net Framework 4.0文件夹。问题来了,当我把这个应用程序移动到一个只有4.0的机器上时,它不会启动并产生错误,因为WindowState={Binding WindowState},您不能在4.0中完成,但是您可以在4.5中完成。我需要它在我的开发框中抛出异常,为什么呢?我的假设是,尽管我尽了最大的努力,但如果它们存在,它会使用4.5个dlls。我怎样才能使它真正使用4.0而不卸载4.5?

Update

更新

To repro this install .NET Framework 4.5 and create a WPF project targeting .NET Framework 4.0. Bind the WindowState to a property in a VM or code behind make this property have a public get and private set. .NET Framework 4.5 handles this just fine even when Mode=TwoWay must ignore the set .NET Framework 4 doesn't and throws an exception: "A TwoWay or OneWayToSource binding cannot work on the read-only property 'State' of type...". On the box with .NET Framework 4.5 works like a charm try it on a machine with only .NET Framework 4.0 and it blows up... So any ideas on how to really target 4.0 when 4.5 is installed?

为了repro这个安装。net Framework 4.5,并创建一个WPF项目,目标是。net Framework 4.0。WindowState绑定到一个属性在一个VM或代码背后使这个属性有公共和私人设置。net Framework 4.5处理这种很好即使模式= TwoWay必须忽略。net框架集4不抛出异常:“TwoWay或OneWayToSource绑定不能只读属性的状态类型……”。在。net Framework 4.5的盒子上,它像一个符咒一样在一个只有。net Framework 4.0的机器上试用。那么,在安装4.5时,如何实现4.0的目标呢?

Bug report to MS here: https://connect.microsoft.com/VisualStudio/feedback/details/774694/targeting-net-framework-4-0-when-4-5-doesnt-seem-to-work

Bug报告到MS这里:https://connect.microsoft.com/visualstudio/feedback/details/774694 /targeting-net framework-4-0-when-4-5不适合工作。

5 个解决方案

#1


3  

Time to punt this question. I'm no expert on WPF, don't like it much for exactly these kind of problems, debugging dependency property problems is a nightmare. But I'm pretty convinced you are chasing a ghost. WindowState has been a dependency property all the way back to 3.0, nothing special happened to it in 4.5 that I can see or ever heard of.

是时候回答这个问题了。我不是WPF的专家,对这些问题不太喜欢,调试依赖属性问题是一场噩梦。但我确信你在追鬼。WindowState一直是一个依赖属性一直到3.0,没有什么特别的事情发生在我可以看到或听说过的4.5。

You got some kind of error message that nobody can see that convinced you that it had something to do with the binding. I'm from Missouri, the Show Me State. Well, close enough to Wisconsin.

你得到了一些错误信息没人能看到它让你确信它与绑定有关。我来自密苏里州。嗯,离威斯康辛很近。

Spend more time working on code that gives you a reliable exception message and stack trace that helps you diagnose errors on the machine you deploy to, the one without a debugger to help you figure out what's going wrong. You do so by writing an event handler for the AppDomain.CurrentDomain.UnhandledException event. Log or display the e.ExceptionObject.ToString() return value. It gives you the exception message and the Holy Stack Trace. If that doesn't help then update your question with what you saw.

花更多的时间在代码上,这会给您提供一个可靠的异常消息和堆栈跟踪,帮助您诊断部署到的机器上的错误,而没有调试器来帮助您判断出哪里出了问题。您可以通过为AppDomain.CurrentDomain编写一个事件处理程序。UnhandledException事件。日志或显示. exceptionobject . tostring()返回值。它提供了异常消息和神圣堆栈跟踪。如果这不能帮助你用你所看到的来更新你的问题。

#2


3  

This appears to be a bug in .NET Framework 4.5 and it should throw the exception but with .NET Framework 4.5 installed there is no way to have your application run on .NET framework 4.0 it will always use 4.5.

这似乎是。net Framework 4.5中的一个bug,它应该抛出一个异常,但是如果安装了。net Framework 4.5,就没有办法让你的应用程序运行在。net Framework 4.0中,它将始终使用4.5。

See this reported bug for more info: http://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding

请参阅本文报告的bug,以获得更多信息:http://connect.microsoft.com/visualstudio/feedback/details/773682 /wpf-property with-private- setteris -update -by-a-twoway绑定。

#3


0  

You said you can't reproduce this in a test project. So that implies that it may be something that should work fine in 4.0 right? You might have some combination of code that is crashing on a bug in 4.0, that was fixed in 4.5. When you target 4.0, you will only get warnings when you try to use API's/features that the compiler can determine are not supported in 4.0.

你说你不能在一个测试项目中复制这个。这意味着它可能在4.0中运行良好,对吧?您可能有一些代码组合在4.0中崩溃,这是在4.5中修复的。当您目标4.0时,当您尝试使用编译器可以确定的API /特性时,您只会得到警告。

Something that should work in 4.0 may crashed due to some rarely seen bug, and then fixed in 4.5. When your 4.0 targeted app runs under 4.5 environment, it will be affected by bug fixes to features that existed in 4.0.

一些应该在4.0中工作的东西可能会因为一些罕见的bug而崩溃,然后在4.5中修复。当您的4.0目标应用程序在4.5环境下运行时,它将受到4.0中存在的缺陷修复的影响。

There may be an update for 4.0 that includes the bug fix, so as not to require 4.5 upgrade if users are adverse to that for some reason. So it might not even be a 4.5 change, but simply a coincidence that some users don't have all of the updates available for 4.0(which would have been cumulatively includes in your 4.5).

可能会有一个4.0版本的更新,包括bug修复,如果用户因为某些原因而对它不利,那么就不需要升级到4.5。因此,它甚至可能不是一个4.5的更改,但仅仅是一个巧合,一些用户并没有所有的更新可用到4.0(这将在您的4.5中累计包含)。

These kind of cases I've rarely encountered, but do happen sometimes and are the reason people who support desktop .NET applications are notorious for asking users to update there .NET framework as a first try at solving odd issues before spending time troubleshooting.

我很少遇到这种情况,但有时确实会出现这种情况,这也是支持桌面. net应用程序的人之所以臭名昭著的原因,是因为他们要求用户更新。net framework作为第一次尝试解决一些奇怪的问题,然后再花时间进行故障排除。

Sometimes the opposite occurs. Your code only works due to some bug or poor behavior of a .NET API, and later an update cleans this up, perhaps tightening security somewhere is the most often thing I've seen, and your code suddenly breaks due to a minor version update of .NET.

有时情况恰恰相反。你的代码只会因为一个。net API的错误或不良行为而起作用,然后更新会清理这个,也许在某个地方加强安全是我见过的最常见的事情,而你的代码会因为。net的一个小版本更新而突然中断。

#4


0  

.Net 4.5 replaces .net 4.0 with new, same-named libraries, that actually have some fixes. That's short answer.

.net 4.0使用新的、同命名的库来替代。net 4.0,它实际上有一些补丁。这是简短的回答。

Unlike earlier versions, updating .net 4 to 4.5 replaces files, instead of adding sided by side files. Even if you have folder like this Windows/Microsoft.Net/Framework/v40/ , After update, there is a change in this folder. Files are changed, some errors were handled in .net without developer's concern.

与以前的版本不同,更新。net 4到4.5替代了文件,而不是添加了侧边文件。即使你有像Windows/微软这样的文件夹。Net/Framework/v40/,更新后,这个文件夹有一个更改。文件被修改,一些错误在。net中被处理,没有开发人员的关注。

How to target 4.0 framework using .net 4.5 ? I still don't know, but I'm still digging

如何使用。net 4.5实现4.0框架?我还是不知道,但我还在挖。

Suggested read on this topic:

建议阅读本主题:

Scott Hanselman : http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

Scott Hanselman:http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

Rick Strahl: http://weblog.west-wind.com/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40

里克特拉:http://weblog.west-wind.com/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40

And similar problem, created by me: https://*.com/questions/26483168/errors-on-net-4-0-dont-appear-on-net-4-5

还有类似的问题,由我创建:https://*.com/questions/26483168/errors-on-net-4-0-dont- -on-net-4-5。

#5


0  

The solution:

解决方案:

I've got the same problem when installed VS2017 after VS2015: Framework 4.0 just disappeared from project target list.

在VS2015之后安装VS2017时,我遇到了同样的问题:框架4.0从项目目标列表中消失了。

Following some comments around here I've tried with NuGet package: Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.4 and bin fix for 1.0.1.

在这里,我试用了NuGet软件包:microsoft.codedom.provider。DotNetCompilerPlatform 1.0.4和bin fix为1.0.1。

Don't do that! My build time went ~300% up for the same project. It was disaster.

别干那事!我的构建时间在同一个项目中增长了300%。这是灾难。

I see that 4.5 is an "in place replacement" for 4.0 However this does not explain why I cant see both options in my target frameworks combo.

我看到4.5是4.0的“替代”,但是这并不能解释为什么我不能在我的目标框架组合中看到两个选项。

I was reading the same mantra all around the web. It's simply not answer to the problem. Framework 4.0 is a must for any industrial machinery related software - because it runs on Windows XP, while .NET 4.5. is useless in my scenario, and probably for many other real-life stuff.

我在网上看到了同样的咒语。这根本不是问题的答案。对于任何与工业机械相关的软件来说,框架4.0都是必须的——因为它运行在Windows XP上,而。net 4.5。在我的场景中是无用的,可能还有很多其他现实生活中的东西。

The solution is simple: You just have to download and install Visual Studio 2013 Express from official web page: https://www.microsoft.com/en-us/download/details.aspx?id=44914

解决方法很简单:你只需从官方网页下载并安装Visual Studio 2013 Express: https://www.microsoft.com/en-us/download/details.aspx?

After installing it, just open your VS2015 and you'll see 4.0 again.

安装完毕后,打开VS2015,您将再次看到4.0。

在安装框架4.5时,目标是。net Framework 4。

... "In place replacement ..." my....

…“代替…”我的


This is re-post of answer I gave on a duplicate question. I'm posting here since this thread got more attention and existing answers here give no solution for the issue.

这是我在重复的问题上给出的回答。我在这里发帖,因为这条线得到了更多的关注,这里的现有答案并没有解决这个问题。

#1


3  

Time to punt this question. I'm no expert on WPF, don't like it much for exactly these kind of problems, debugging dependency property problems is a nightmare. But I'm pretty convinced you are chasing a ghost. WindowState has been a dependency property all the way back to 3.0, nothing special happened to it in 4.5 that I can see or ever heard of.

是时候回答这个问题了。我不是WPF的专家,对这些问题不太喜欢,调试依赖属性问题是一场噩梦。但我确信你在追鬼。WindowState一直是一个依赖属性一直到3.0,没有什么特别的事情发生在我可以看到或听说过的4.5。

You got some kind of error message that nobody can see that convinced you that it had something to do with the binding. I'm from Missouri, the Show Me State. Well, close enough to Wisconsin.

你得到了一些错误信息没人能看到它让你确信它与绑定有关。我来自密苏里州。嗯,离威斯康辛很近。

Spend more time working on code that gives you a reliable exception message and stack trace that helps you diagnose errors on the machine you deploy to, the one without a debugger to help you figure out what's going wrong. You do so by writing an event handler for the AppDomain.CurrentDomain.UnhandledException event. Log or display the e.ExceptionObject.ToString() return value. It gives you the exception message and the Holy Stack Trace. If that doesn't help then update your question with what you saw.

花更多的时间在代码上,这会给您提供一个可靠的异常消息和堆栈跟踪,帮助您诊断部署到的机器上的错误,而没有调试器来帮助您判断出哪里出了问题。您可以通过为AppDomain.CurrentDomain编写一个事件处理程序。UnhandledException事件。日志或显示. exceptionobject . tostring()返回值。它提供了异常消息和神圣堆栈跟踪。如果这不能帮助你用你所看到的来更新你的问题。

#2


3  

This appears to be a bug in .NET Framework 4.5 and it should throw the exception but with .NET Framework 4.5 installed there is no way to have your application run on .NET framework 4.0 it will always use 4.5.

这似乎是。net Framework 4.5中的一个bug,它应该抛出一个异常,但是如果安装了。net Framework 4.5,就没有办法让你的应用程序运行在。net Framework 4.0中,它将始终使用4.5。

See this reported bug for more info: http://connect.microsoft.com/VisualStudio/feedback/details/773682/wpf-property-with-private-setter-is-updated-by-a-twoway-binding

请参阅本文报告的bug,以获得更多信息:http://connect.microsoft.com/visualstudio/feedback/details/773682 /wpf-property with-private- setteris -update -by-a-twoway绑定。

#3


0  

You said you can't reproduce this in a test project. So that implies that it may be something that should work fine in 4.0 right? You might have some combination of code that is crashing on a bug in 4.0, that was fixed in 4.5. When you target 4.0, you will only get warnings when you try to use API's/features that the compiler can determine are not supported in 4.0.

你说你不能在一个测试项目中复制这个。这意味着它可能在4.0中运行良好,对吧?您可能有一些代码组合在4.0中崩溃,这是在4.5中修复的。当您目标4.0时,当您尝试使用编译器可以确定的API /特性时,您只会得到警告。

Something that should work in 4.0 may crashed due to some rarely seen bug, and then fixed in 4.5. When your 4.0 targeted app runs under 4.5 environment, it will be affected by bug fixes to features that existed in 4.0.

一些应该在4.0中工作的东西可能会因为一些罕见的bug而崩溃,然后在4.5中修复。当您的4.0目标应用程序在4.5环境下运行时,它将受到4.0中存在的缺陷修复的影响。

There may be an update for 4.0 that includes the bug fix, so as not to require 4.5 upgrade if users are adverse to that for some reason. So it might not even be a 4.5 change, but simply a coincidence that some users don't have all of the updates available for 4.0(which would have been cumulatively includes in your 4.5).

可能会有一个4.0版本的更新,包括bug修复,如果用户因为某些原因而对它不利,那么就不需要升级到4.5。因此,它甚至可能不是一个4.5的更改,但仅仅是一个巧合,一些用户并没有所有的更新可用到4.0(这将在您的4.5中累计包含)。

These kind of cases I've rarely encountered, but do happen sometimes and are the reason people who support desktop .NET applications are notorious for asking users to update there .NET framework as a first try at solving odd issues before spending time troubleshooting.

我很少遇到这种情况,但有时确实会出现这种情况,这也是支持桌面. net应用程序的人之所以臭名昭著的原因,是因为他们要求用户更新。net framework作为第一次尝试解决一些奇怪的问题,然后再花时间进行故障排除。

Sometimes the opposite occurs. Your code only works due to some bug or poor behavior of a .NET API, and later an update cleans this up, perhaps tightening security somewhere is the most often thing I've seen, and your code suddenly breaks due to a minor version update of .NET.

有时情况恰恰相反。你的代码只会因为一个。net API的错误或不良行为而起作用,然后更新会清理这个,也许在某个地方加强安全是我见过的最常见的事情,而你的代码会因为。net的一个小版本更新而突然中断。

#4


0  

.Net 4.5 replaces .net 4.0 with new, same-named libraries, that actually have some fixes. That's short answer.

.net 4.0使用新的、同命名的库来替代。net 4.0,它实际上有一些补丁。这是简短的回答。

Unlike earlier versions, updating .net 4 to 4.5 replaces files, instead of adding sided by side files. Even if you have folder like this Windows/Microsoft.Net/Framework/v40/ , After update, there is a change in this folder. Files are changed, some errors were handled in .net without developer's concern.

与以前的版本不同,更新。net 4到4.5替代了文件,而不是添加了侧边文件。即使你有像Windows/微软这样的文件夹。Net/Framework/v40/,更新后,这个文件夹有一个更改。文件被修改,一些错误在。net中被处理,没有开发人员的关注。

How to target 4.0 framework using .net 4.5 ? I still don't know, but I'm still digging

如何使用。net 4.5实现4.0框架?我还是不知道,但我还在挖。

Suggested read on this topic:

建议阅读本主题:

Scott Hanselman : http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

Scott Hanselman:http://www.hanselman.com/blog/NETVersioningAndMultiTargetingNET45IsAnInplaceUpgradeToNET40.aspx

Rick Strahl: http://weblog.west-wind.com/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40

里克特拉:http://weblog.west-wind.com/posts/2012/Mar/13/NET-45-is-an-inplace-replacement-for-NET-40

And similar problem, created by me: https://*.com/questions/26483168/errors-on-net-4-0-dont-appear-on-net-4-5

还有类似的问题,由我创建:https://*.com/questions/26483168/errors-on-net-4-0-dont- -on-net-4-5。

#5


0  

The solution:

解决方案:

I've got the same problem when installed VS2017 after VS2015: Framework 4.0 just disappeared from project target list.

在VS2015之后安装VS2017时,我遇到了同样的问题:框架4.0从项目目标列表中消失了。

Following some comments around here I've tried with NuGet package: Microsoft.CodeDom.Providers.DotNetCompilerPlatform 1.0.4 and bin fix for 1.0.1.

在这里,我试用了NuGet软件包:microsoft.codedom.provider。DotNetCompilerPlatform 1.0.4和bin fix为1.0.1。

Don't do that! My build time went ~300% up for the same project. It was disaster.

别干那事!我的构建时间在同一个项目中增长了300%。这是灾难。

I see that 4.5 is an "in place replacement" for 4.0 However this does not explain why I cant see both options in my target frameworks combo.

我看到4.5是4.0的“替代”,但是这并不能解释为什么我不能在我的目标框架组合中看到两个选项。

I was reading the same mantra all around the web. It's simply not answer to the problem. Framework 4.0 is a must for any industrial machinery related software - because it runs on Windows XP, while .NET 4.5. is useless in my scenario, and probably for many other real-life stuff.

我在网上看到了同样的咒语。这根本不是问题的答案。对于任何与工业机械相关的软件来说,框架4.0都是必须的——因为它运行在Windows XP上,而。net 4.5。在我的场景中是无用的,可能还有很多其他现实生活中的东西。

The solution is simple: You just have to download and install Visual Studio 2013 Express from official web page: https://www.microsoft.com/en-us/download/details.aspx?id=44914

解决方法很简单:你只需从官方网页下载并安装Visual Studio 2013 Express: https://www.microsoft.com/en-us/download/details.aspx?

After installing it, just open your VS2015 and you'll see 4.0 again.

安装完毕后,打开VS2015,您将再次看到4.0。

在安装框架4.5时,目标是。net Framework 4。

... "In place replacement ..." my....

…“代替…”我的


This is re-post of answer I gave on a duplicate question. I'm posting here since this thread got more attention and existing answers here give no solution for the issue.

这是我在重复的问题上给出的回答。我在这里发帖,因为这条线得到了更多的关注,这里的现有答案并没有解决这个问题。