Cannot change Target Framework on Several Projects From v4.0 to V4.5 or 4.5.1

怎甘沉沦 提交于 2019-12-17 19:19:27

问题


I have several projects in a large solution that won't convert to V4.5.1 (or even V4.5). Most did, but obviously I need to get all of them converted. The GUI in Visual Studio says that it did it and reloads the project, but if you go back into the properties it still says V4 and it won't compile because of dependencies that converted properly and are V4.5.1

I tried manually updating the .csproj files and it says 4.5.1 as the target framework, and I even updated the app.config/web.config to point to the right version, however Visual Studio's property page still says .NET 4 and is throwing compile errors because it can't access the ones that successfully updated to 4.5.1

What am I missing in the process to get these updated? I've tried VS.net 2012 and 2013 and both do the same thing.


回答1:


In hopes that this helps others:

In our case, the issue was that we were referencing a custom targets file that was created for the entire solution. even though the project was getting updated, the custom targets file was overriding it thus preventing the project from getting updated.

Updated the targets file to point to .net 4.5 and everything was fine.




回答2:


For me, the solution was to remove all the extraneous <PropertyGroup> sections from the .csproject file - except the first one.

VS 2015 was setting the <TargetFramework> to 4.5.1 on only one of them (not the first one).




回答3:


I had a similar issue. Turns out the DLLs were built for target framework 4.5.1, but the project I was working in was built for 4.5 only. There were some suppressed warning messages when I compiled. When I showed compile warnings, that was the hint that told me what was going on.

I recompiled the DLLs for framework 4.5, and then the DLLs copied automatically without needing additional references to the assemblies.




回答4:


After two days of suffering, I have created a new project, targeted .NET 4.5 and then manually copied all files from the existing project. Made sure new project compiles. Removed old project. Moved new project into the directory of the old project so that I can reverse merge into trunk. Job done.

Project I was upgrading was an old WPF project with thousands (no kidding) XAML files in a single project. It also had a release preview of MvvmLight (years old) and an older version of Prism along with a range of other libraries. All and all the project is a mess and somebody must have done something really stupid to make targeting .NET 4.5 this difficult.




回答5:


In my case I was working with projects designed for SharePoint 2010. Apparently the project template restricts the .NET target framework version which can be selected.

As I was trying to compile a SharePoint 2016 server, once I got the beta templates downloaded for 2016, Visual Studio automatically prompted me to upgrade these projects when trying to open the solution again. Hope this helps someone.

Preview bits for SharePoint 2016 are available here: https://www.microsoft.com/en-us/download/details.aspx?id=49972



来源:https://stackoverflow.com/questions/21316795/cannot-change-target-framework-on-several-projects-from-v4-0-to-v4-5-or-4-5-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!