简体   繁体   English

将.NET项目从4.5转换为4.0的最简单方法?

[英]easiest way to convert .NET project from 4.5 to 4.0?

I have a .NET application that I built in 4.5, which has references to a bunch of libraries that were built in 4.5, which themselves have references to 4.5, etc. A user group that I'm trying to distribute the application to is having problems running the executable because they have 4.0 installed; 我有一个我在4.5中构建的.NET应用程序,它引用了一堆用4.5构建的库,它们本身引用了4.5等。我正在尝试分发应用程序的用户组正在使用运行可执行文件的问题,因为它们已安装4.0; in particular, they're getting a MissingMethodException: 特别是,他们遇到了MissingMethodException:

Method not found: 'System.Type System.Runtime.InteropServices.Marshal.GetTypeFromCLSID(System.Guid)'.

Because we may have trouble getting each user upgraded to 4.5 (as none of them have admin permissions on their machines and this would require a separate upgrade request for each user), I'm looking at finding an easy way to rebuild the project as 4.0. 因为我们可能无法将每个用户升级到4.5(因为他们都没有在他们的计算机上拥有管理员权限,这需要为每个用户单独升级请求),我正在寻找一种简单的方法来重建项目为4.0 。 This seems to require that I rebuild every library and its referenced libraries in 4.0; 这似乎要求我在4.0中重建每个库及其引用的库; is there an easier way to do this than going through each library one by one and building a 4.0 version? 有没有比通过逐个浏览每个库并构建4.0版本更简单的方法? I'm thinking maybe like a one-click option for "Rebuild all referenced libraries in target framework" or something like that. 我想也许就像“重建目标框架中所有引用的库”之类的一键式选项或类似的东西。

When I use Visual Studio, I right click on the project, change the framework, fix the References and recompile. 当我使用Visual Studio时,我右键单击项目,更改框架,修复引用并重新编译。 Usually straight forward. 通常直截了当。

If you have dependencies on .Net 4.5 DLLs then you will need to also get .Net 4.0 versions of those if you want to successfully downgrade your project. 如果您依赖.Net 4.5 DLL,那么如果您想成功降级项目,还需要获得.Net 4.0版本。 A .Net project can only reference .Net DLLs up to the same version of .Net as the referencing assembly. .Net项目只能将.Net DLL引用到与引用程序集相同的.Net版本。

The easiest way to do this is to use something like NuGet to manage your dependencies. 最简单的方法是使用NuGet之类的东西来管理依赖项。 Note that when you change the target framework version of your project in VS you will need to uninstall and re-install dependencies with NuGet as NuGet does not automatically do this for you when you change the target framework version. 请注意,当您在VS中更改项目的目标框架版本时,您需要使用NuGet卸载并重新安装依赖项,因为当您更改目标框架版本时,NuGet不会自动为您执行此操作。

Of course if all the dependencies are to your own code and you aren't publishing this through a dependency management system like NuGet you will need to downgrade all your other code to .Net 4.0 as well 当然,如果所有依赖项都是您自己的代码,并且您没有通过像NuGet这样的依赖管理系统发布它,那么您需要将所有其他代码降级到.Net 4.0

Please, have a look at this MSDN page to correctly switch your project to a lower target framework without problems! 请看一下这个MSDN页面,以正确地将项目切换到较低的目标框架而不会出现问题! It is a little bit outdated for what concerns versions, but the process is the same described! 对于涉及版本的问题,它有点过时,但过程是相同的描述!

This is based on my experience. 这是基于我的经验。 I had an application initially created in .net framework 4.5 but I wanted to convert it in .net framework 4.0. 我有一个最初在.net framework 4.5中创建的应用程序,但我想在.net framework 4.0中进行转换。 I created new project initially created 4.0 and then I did copy and paste of all the forms and controls of my previous application and it works. 我创建了最初创建4.0的新项目,然后我复制并粘贴了我以前的应用程序的所有表单和控件,它的工作原理。 Framework 4.5 is using Aero2 and 4.0 is Aero... Good Luck :) Framework 4.5正在使用Aero2而4.0则是Aero ...祝你好运:)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM