Why does the .NET tab in the 'Add Reference' dialog in Visual Studio not list the contents of the GAC?

余生颓废 提交于 2019-12-22 09:29:56

问题


Duplicate of: Getting assemblies to show in the .NET tab of Add Reference

So, I'm using Visual C# 2008 Express Edition and I've just been on a bit of a detour as I found out that my assumption that the .NET tab of the 'Add Reference' dialog lists the contents of the GAC was incorrect.

This was a bit of a problem for me as the assembly that I wanted to reference from my project was only available in the GAC. (It was Microsoft.XNA.Framework v2.0 obtained from the XNA 2.0 redistributalbe and as far as I could see it installed only into the GAC).

I worked round the problem by setting the reference to Microsoft.XNA.Framework manually in the .csproj file and then getting a copy of the dll out of the cache. I was then able to create a directory for the DLL, add it to Visual Studio's list of assembly directories in the registry and then voila! I could see it in the .NET tab.

This all seems like a bit of a faff to me and I don't think that my initial assumption (that the .NET tab shows the contents of the GAC) was that unreasonable or would be that uncommon. Can someone who knows more than me tell me

  • why the contents of the GAC aren't shown? The documentation just says that they are not, but is there a good reason?
  • is there actually a way to get the entire contents of the GAC to be listed? A tick box I've missed somewhere?

Any info much appreciated.


回答1:


You're making the assumption that the .NET tab means GAC but it doesn't. It means installed assemblies, which may or may not be in the GAC. Some installations go under Program Files and those assemblies are then visible in the .NET tab.

When you add a reference to a project (ignore Web Site projects, as they're a bastard child anomaly and need to DIAF) the .NET runtime will locate that assembly using a cascading search that starts in the executable directory, checks the PATH environment variable and ends in the GAC. I don't have a link, but there is at least one good article on MSDN that specifically explains this.

The above may not seem to directly correlate here, but it does in the sense that when you're developing you can make a reference to an assembly somewhere on your development machine, but then when you distribute your application to another machine for production use, that assembly doesn't necessarily have to be in the same place as it was on your development machine. When you're developing you can have the assembly local, or in Program Files, but then on another machine if that assembly is in the GAC then your program should just work.

(Typically when you install an SDK the installer will be smart enough to create the registry entries needed to show the dll's in the .NET tab. Your XNA framework example may come down to you installing the runtime package instead of the SDK or something.)

Hope that helps.




回答2:


Download and use the Muse VSReferences extensions. It will do all of this automatically for you

s



来源:https://stackoverflow.com/questions/871984/why-does-the-net-tab-in-the-add-reference-dialog-in-visual-studio-not-list-th

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