Multiple .NET assembly directories on my computer (which one do I use?)
Perhaps a dump question (But I'm not a super experienced user of .NET), but it seems I have identical (or nearly so) versions of .NET 4.0 in two different places on my machine:
- C:\Windows\Micr开发者_高级运维osoft.NET\Framework\v4.0.30319
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0
In visual studio, when I go to add a reference for a C++/CLI project, it takes me to directory #2.
Also in visual studio, I can specify an assembly path to resolve #using References, (which allows me to use the symbolic paths in the property pages). There in can use the macro $(FrameworkDir) which resolves (at least on my machine) to C:\Windows\Microsoft.NET\Framework\ which is basically directory #1.
So which one should I use?
First and foremost, you should use the Add New Reference dialog, .NET tab. It is configured by the installer to present the correct ones.
For 4.0, you should always use 2, it contains the version isolated reference assemblies. They are special, not just a copy but stripped down to the metadata. They prevent you from accidentally using a public method or property that was added in a service pack. And break your program when it runs on a machine without the service pack. WaitHandle.WaitOne(int) was infamous for that, only available in .NET 2.0 SP2
This is new concept that comes since .NET Framework 3.5. You can read more about that in this blog post. I assume that your platform is x64. Hence, you have .NET Framework for x86 and x64 installed on your machine in both Program Files folders.
From here
It seems for Managed C++ projects, the compiler will attempt to import dependencies of referenced assemblies, which makes sense, but it is unable to recognize assemblies it has already imported. Common dependencies will then conflict with themselves as they are being imported once with the original reference, then again if another reference has that common project as a dependency.
So in this example, "Common" is imported into "Forms". Then "Common" is imported into "Main". When "Main" imports "Forms", however, it then imports the dependencies of "Forms"; "Common", a second time.
The fix is to use the "Use Dependencies In Build" and "Use In Build" flags on each VC project references (via the VC properties sheet), and toggle them as appropriate for your case to resolve this error.
精彩评论