none
Find the folder that contains the .Net assembly files for some version of .Net RRS feed

  • Question

  • This is a question that I have looked into before but found little published details on.

    Basically, how can one (an executing app) discover the actual system folder where the assemblies for a .Net version are stored?

    For .Net 3.5 the folder is: C:\Windows\Microsoft.NET\Framework\v2.0.50727 and for .Net 4 it is: C:\Windows\Microsoft.NET\Framework\v4.0.30319

    A running app can look at Environment.Version and use Major, Minor and Build (ignoring Revision) to create the name of the folder for the version of the CLR it is running.

    For .Net 3.5 that version is: 2.0.50727.3615 (but the latter part, the revision plays no role in the folder name).

    But this is all pretty bewildering, I mean what does it mean to "target" .Net 3.5 if the actual version folder is 2?

    If you have a simple project built against .Net 4 in VS 2010 and do "Add Reference" the displayed dialog has some info near the top that says "Filtered to: .Net Framework 4".

    But as you scroll down the list of .Net assemblies many have (Runtime) versions like v1.1.4322 or v2.0.50727 or v1.0.3705 etc.

    So how does VS know which files to pull from which version folder?

    Does it list all .Net 4 assemblies found in the v4.0.30319 folder and then add other assemblies from the other version folders if they are not in the v4 folder?

    Bear in mind that Add Reference does NOT look at the GAC.

    I'd like to read some detailed docs on this because there appears to be formal API or classes for doing all this.

     

    Thanks

    Cap'n

     

     

     

     

     

    Tuesday, June 14, 2011 5:39 PM

Answers

  • The .NET 2.0 family includes .NET 3.5. That's all basically the same runtime, and the 3.0 and 3.5 updates added new base class functionality, but not an actual new framework version. That's why 3.5 and 2.0 are "the same". 4.0 is a new runtime.

    VS doesn't pull assemblies from any of those GAC folders at build time as far as I know.  It uses the .NET SDK framework assemblies.  Generally speaking, Visual Studio versions are bound to a (SDK) version of the framework, sometimes giving you the choice of two. I think you may be missing a crucial point here, which is that the GAC is a deployment choice, not a repository for development assemblies, and where Microsoft chooses to locate it for use at runtime is mostly irrelevant. The runtime loader for whatever framework you use knows where to get them from.  It's no different from other development like C++ where you reference .LIB files in an SDK at build time, and then at runtime Windows uses some search algorithm to find the corresponding actual Dll. In managed code you reference assemblies at build time, but they may not be the exact same ones used when you run because that depends on assembly loading rules.

    Is there an actual problem you're trying to solve? 


    Phil Wilson
    • Marked as answer by Alexander Sun Thursday, June 23, 2011 2:48 AM
    Tuesday, June 14, 2011 6:42 PM
  • Hi Captain,

     

    Thank you for your reply.

     

    First, the folder “Windows\Microsoft.Net\v4.0.30319” is the installation folder of .NET Framework 4, and the folder “Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0” is the assemblies to reference in your code. If you have any problems about GAC, I recommend you read these two articles:

    http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx

    http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx

     

    why are many files in the latter two folder different sizes? Because these two folders store different files. One stores installation files. Another stores the assemblies to reference in your code.

     

    For my limited knowledge, if you have any concerns about assemblies of .NET Framework, you can go to the CLR forum to ask for helps. There are many experienced experts on your issue.

     

    I hope this helps.

     

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alexander Sun Thursday, June 23, 2011 2:48 AM
    Monday, June 20, 2011 9:05 AM

All replies

  • The .NET 2.0 family includes .NET 3.5. That's all basically the same runtime, and the 3.0 and 3.5 updates added new base class functionality, but not an actual new framework version. That's why 3.5 and 2.0 are "the same". 4.0 is a new runtime.

    VS doesn't pull assemblies from any of those GAC folders at build time as far as I know.  It uses the .NET SDK framework assemblies.  Generally speaking, Visual Studio versions are bound to a (SDK) version of the framework, sometimes giving you the choice of two. I think you may be missing a crucial point here, which is that the GAC is a deployment choice, not a repository for development assemblies, and where Microsoft chooses to locate it for use at runtime is mostly irrelevant. The runtime loader for whatever framework you use knows where to get them from.  It's no different from other development like C++ where you reference .LIB files in an SDK at build time, and then at runtime Windows uses some search algorithm to find the corresponding actual Dll. In managed code you reference assemblies at build time, but they may not be the exact same ones used when you run because that depends on assembly loading rules.

    Is there an actual problem you're trying to solve? 


    Phil Wilson
    • Marked as answer by Alexander Sun Thursday, June 23, 2011 2:48 AM
    Tuesday, June 14, 2011 6:42 PM
  • The .NET 2.0 family includes .NET 3.5. That's all basically the same runtime, and the 3.0 and 3.5 updates added new base class functionality, but not an actual new framework version. That's why 3.5 and 2.0 are "the same". 4.0 is a new runtime.

    VS doesn't pull assemblies from any of those GAC folders at build time as far as I know.  It uses the .NET SDK framework assemblies.  Generally speaking, Visual Studio versions are bound to a (SDK) version of the framework, sometimes giving you the choice of two. I think you may be missing a crucial point here, which is that the GAC is a deployment choice, not a repository for development assemblies, and where Microsoft chooses to locate it for use at runtime is mostly irrelevant. The runtime loader for whatever framework you use knows where to get them from.  It's no different from other development like C++ where you reference .LIB files in an SDK at build time, and then at runtime Windows uses some search algorithm to find the corresponding actual Dll. In managed code you reference assemblies at build time, but they may not be the exact same ones used when you run because that depends on assembly loading rules.

    Is there an actual problem you're trying to solve? 


    Phil Wilson


    Hello Phil;

    Yes I am fully aware of the GAC and its purpose, and I know its role.

    The problem is this I have created a small IDE tool for allowing users to write and compile code.

    That tool allows a user to add references just like VS2010 does, so that they can compile their code.

    My Add Reference dialog needs to populate the list of assemblies that a user can add, including all of the installed Micorosft one etc. I have algorithms for this that seem fine (I know where to look in the registry for the names of the folder in which assemblies are stored by third parties).

    But there are still some unresolved issues here, one of them being how to get all of the framework assemblies into my list depending upon the version of .Net to be used by my user.

    There is no formal support classes or anything for any of this and there really should be some documentation for it.

    First getting the actual disk folder path for framework assemblies based upon "version" is somewhat of a hack (I use hard coded folder name with version appended).

    Second, how can one go from "I want to use .Net Framework 4" to "I want to use assemblies in the folder v4.0.30319"?  Is there a way? where is the mapping metadata that maps 4 to 4.0.30319 or that maps 3.5 to 2.0.50727 and so on.

    Third, as you point out the .Net 2.0 "family" includes .Net 3 and .Net 3.5 but how does one "know" this, where is that relationship data stored? in the registry? (I can't find it).

    Fourth, populating the list (for my Add Reference) for version 4, must include assemblies from all earlier version that are not present in v 4,

    Fifth, there is inconsistency in the way MS manage this, for example in the registry we find that under HKLM\SOFTWARE\Microsoft is subkey named .NETFramework, beneath there is "Assembly Folder" which are the folders that third parties own asseblies are to be found by Visual Studio (VS uses these registry keys to populate its own Add Reference list).

    You will see also a v3.0 and a v3.5 but no v4.0 !

    Instead, (above AssemblyFolders) we find v4.0.30319 which is empty.

    In addition we are told that MS now (as standard??) puts copies of all assemblies into C:\Program Files (x86)\Reference Assemblies, where there are indeed copies of assemblies (for v3.5 and v4).

    So this is all very bewildering and pretty much undocumented, and for those of us needing to include Add Reference like functionality to our own apps, it is very complicated to understand.

    The basic challenge therefore is what is the overall algorithm/heuristic one must use to correctly populate their own Add Reference dialog so that they too can list all of the .Net assemblies that are seen in Visual Studio's Add Reference?

    What I have works pretty well and tooks weeks of digging and experimenting, but for .Net 4 it is failing because the registry has no v4.0 subkey, it only has v3.0 and v3.5 so I am forced to hardcode a path or something...

    Cap'n

    PS: There are thus THREE copies of the .Net systen assemblies on a machine (e.g. for version 4 of .Net)

    1. Inside the GAC.

    2. In the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0 folder.

    3. IN the C:\Windows\Microsoft.NET\Framework\v4.0.30319 folder

    Also the files in 2. and 3. are NOT the same (size) adding yet more to the sheer bewilderment of all this.

     


    Tuesday, June 14, 2011 7:48 PM
  • Hi Captain,

     

    Welcome to the MSDN forum.

     

    First, In my opinion, what you want is the method that how to get all of the framework assemblies you need, so I recommend you read this article I think is helpful: http://blogs.msdn.com/b/msbuild/archive/2007/04/12/new-reference-assemblies-location.aspx

     

    Second, the version 4.0.30319 you mentioned is the version of .NET Framework 4 actually.

     

    Third, you said “populating the list (for my Add Reference) for version 4, must include assemblies from all earlier version that are not present in v 4”. Could you please let me know why you want to list all assemblies from all earlier version to populate the list for .NET Framework 4?

     

    Fourth, from my machine, under “HKLM\SOFTWARE\Microsoft\.NETFramework”, I am able to see a v2.0.50727, v3.0 and v4.0.30319. What is your OS?

     

    Fifth, the reference assemblies included the .NET Framework 4 Client Profile which can be found in \Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client. For more information about the Client Profile, see .NET Framework Client Profile. Under folder “Windows\Microsoft.NET\Framework64\v4.0.30319”, you will find some components of .NET Framework 4 like C# compiler .

     

    If you have any other concerns, please feel free to let me know.

     

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 16, 2011 9:44 AM
  •  

    Hi Captain,

     

     

     

    Welcome to the MSDN forum.

     

    First, In my opinion, what you want is the method that how to get all of the framework assemblies you need, so I recommend you read this article I think is helpful: http://blogs.msdn.com/b/msbuild/archive/2007/04/12/new-reference-assemblies-location.aspx

     

    Second, the version 4.0.30319 you mentioned is the version of .NET Framework 4 actually.

     

    Third, you said “populating the list (for my Add Reference) for version 4, must include assemblies from all earlier version that are not present in v 4”. Could you please let me know why you want to list all assemblies from all earlier version to populate the list for .NET Framework 4?

     

    Fourth, from my machine, under “HKLM\SOFTWARE\Microsoft\.NETFramework”, I am able to see a v2.0.50727, v3.0 and v4.0.30319. What is your OS?

     

    Fifth, the reference assemblies included the .NET Framework 4 Client Profile which can be found in \Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client. For more information about the Client Profile, see .NET Framework Client Profile. Under folder “Windows\Microsoft.NET\Framework64\v4.0.30319”, you will find some components of .NET Framework 4 like C# compiler .

     

    If you have any other concerns, please feel free to let me know.

     

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thanks for the detailed repsonse, here are my answers to your questions Alexander:

    1. Populating the list should include any earlier assemblies that are not supercede by a .Net 4 version. I am unsure what exactly these may be, but that is the intent here, to let the user see all earlier versions for which a .Net 4 version does not exist. If you do Add Reference in VS2010 (for a .Net 4 project) and select the .Net tab you will see (for example) Microsoft.Synchronization (the assembly version itself being 1.0.0.0) and the runtime (it was built for) being v2.0.50727. This assembly does not exist in the .Net 4 folders (either in Windows\Microsoft.Net\v4.0.30319 or in Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0)

    2. Yes I too see that registry folder BUT I was referring to HKLM\SOFTWARE\Microsoft\.NETFramework\Assembly Folders and this has no entry for .Net 4 (but does for v3.0 and v3.5). Also even in the HKLM\SOFTWARE\Microsoft\.NETFramework folder, although ha node exists for v4.0.30319 that key and all subkeys are empty (have no values).

    I read that the "Assembly Folders" reg key is THE place for third parties (and I assumed MS too) to define the path for their reference assemblies, these are the paths that VS itself uses to populate Add Reference for third party components.

    So why now v4.0 node beneath HKLM\SOFTWARE\Microsoft\.NETFramework\Assembly Folders ?

    Overall this is still very confusing and anyone needing to replicate the Add Reference functionality has a lot of work to do trying to make sense and get consistency from all this.

    And WHY do we need THREE copies of these system assemblies: 1) GAC 2) Windows\Microsoft.Net\v4.0.30319 and 3) Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0.

    Having three copies of the same assembly files strikes me as very bad practice given the desire to avoid "DLL Hell" !

    And why are many files in the latter two folder different sizes??

     

    Thanks

    Cap'n

     

     



    Thursday, June 16, 2011 2:20 PM
  • Hi Captain,

     

    Thank you for your reply.

     

    First, the folder “Windows\Microsoft.Net\v4.0.30319” is the installation folder of .NET Framework 4, and the folder “Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0” is the assemblies to reference in your code. If you have any problems about GAC, I recommend you read these two articles:

    http://msdn.microsoft.com/en-us/library/yf1d93sz.aspx

    http://msdn.microsoft.com/en-us/library/yx7xezcf.aspx

     

    why are many files in the latter two folder different sizes? Because these two folders store different files. One stores installation files. Another stores the assemblies to reference in your code.

     

    For my limited knowledge, if you have any concerns about assemblies of .NET Framework, you can go to the CLR forum to ask for helps. There are many experienced experts on your issue.

     

    I hope this helps.

     

    Best Regards,


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Alexander Sun Thursday, June 23, 2011 2:48 AM
    Monday, June 20, 2011 9:05 AM