简体   繁体   中英

Can I have a project which uses .NET Framework 4.5.2 and another project with 4.6.2 in the same solution?

我想创建一个VS解决方案,其项目使用.NET Framework 4.5.2,另一个项目使用4.6.2在同一个VS解决方案中。

Having projects using different versions of .Net in the same solution is fine. When you add references between projects you may have issues. Projects can reference other projects that are at-or-below the version of the referencing project. Ie, a .Net 4.5 project can reference .Net 4.5 projects and lower.

Now if you add a reference to a .Net 4.6.2 project to the .Net 4.5 project, it will not resolve or in other words, the reference simply won't work. Unfortunately, Visual Studio won't stop you (at least at the time of writing) so you need to look for a couple visual cues to let you know something is amiss. One is in the references list under the project in Visual Studio; an exclamation point will show next to your reference like this:

参考视觉提示警告

The other cue will be compile time warnings like this:

编译时间警告

You'll want to keep an eye out for this since it will most likely cause run time issues if you use that assembly in the referencing project which can be a headache to troubleshoot.

Yes, you can have them in the same solution without impact. Now if you mixed versions referencing each other than it gets into a grey area.

If your code is referencing a library that is the same or less than your target framework than you are usually just fine but you should also check if there are any known issues just to be sure. On the reverse side when your code is ref libraries with higher target framework than you can expect some weird things and unexpected errors to crop up.

It depends. I just tried it with 4.5.2 and 4.7.1. As long as the references are in place, you can reference an item in the 4.5.2 framework code from the newer version (4.7.1 in my case). However I don't think it will work the other way around.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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