<p>How can I tell from the assembly name, or assembly class (or others like it), whether an assembly is part of the <a href="http://en.wikipedia.org/wiki/.NET_Framework" rel="noreferrer">.NET</a> framework (that is, <code>System.windows.Forms</code>)?</p>

<p>So far I've considered the PublicKeyToken, and CodeBase properties, but these are not always the same for the whole framework.</p>

<p>The reason I want this information is to get a list of assemblies that my EXE file is using that need to be on client machines, so I can package the correct files in a setup file without using the Visual Studio setup system. The problem is, I don't want to pick up any .NET framework assemblies, and I want it to be an automatic process that is easy to roll out whenever a major update is finished.</p>

<p>The ultimate solution would be that there is an IsFramework property... :)</p>

[{'answer_id': 52161, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': True, 'text': "<p>I suspect that the method both most reliable and most general is going to be the PublicKeyToken.  Yes, there's more than one, but it's going to be a finite list and one that doesn't change very often.</p>\n\n<p>For that matter, you could just have a whitelist of assembly names -- that list, too, will be both finite and static between versions of the framework.</p>\n"}, {'answer_id': 52199, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 1, 'selected': False, 'text': "<p>You could use reflection to look at the publisher of the assembly, and coordinate that with the assembly's path. If you find an assembly whose publisher is Microsoft, and which exists somewhere below <code>C:\\Windows\\Microsoft.NET\\Framework</code> it's a safe bet it's part of the runtime.</p>\n\n<p>On second thought, the publisher may not even be necessary. Anything under that path should be part of the runtime (barring a misbehaving application that's diddling where it shouldn't be).</p>\n"}, {'answer_id': 749535, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>No, it doesn\'t begin with "System". You could check "WindowsBase" which is a framework assembly.</p>\n\n<p>You can\'t also check the PublicKeyToken, because there are other Microsoft assemblies signed with the "default" keys, but they are not part of the .NET Framework (Visual Studio assemblies).</p>\n\n<p>The best way of doing it is to get a collection of installed .NET frameworks and check if the target assembly is part of their RedistList (<code>RedistList\\FrameworkList.xml</code>).</p>\n\n<p>FrameworkList.xml can be found in:</p>\n\n<ul>\n<li>.NET 2.0: C:\\Windows\\Microsoft.NET\\Framework64\\v2.0.50727\\RedistList</li>\n<li>.NET 3.x: C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\v<em>VersionNumber</em>\\RedistList</li>\n<li>.NET 4.x: C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETFramework\\v<em>VersionNumber</em>\\RedistList</li>\n<li>.NET Core: C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework.NETCore\\v<em>VersionNumber</em>\\RedistList</li>\n</ul>\n'}, {'answer_id': 2010078, 'author': 'Jon Turner', 'author_id': 16979, 'author_profile': 'https://Stackoverflow.com/users/16979', 'pm_score': 1, 'selected': False, 'text': "<p>If you know that none of your DLLs will be in the GAC you could check whether each assembly is in the GAC or not.  If it is, don't copy it.  If it isn't, then do copy it.  There is a property on the Assembly class called GlobalAssemblyCache.  This would obviously work better in some situations than in others.</p>\n"}, {'answer_id': 3472112, 'author': 'jpierson', 'author_id': 83658, 'author_profile': 'https://Stackoverflow.com/users/83658', 'pm_score': 3, 'selected': False, 'text': '<p>To accomplish this I\'m using the Product Name embedded within the assembly through the AssemblyProductAttribute.</p>\n\n<pre><code>var attribute = assembly.GetCustomAttributes(typeof(AssemblyProductAttribute), false)[0] as AssemblyProductAttribute;\nvar isFrameworkAssembly = (attribute.Product == "Microsoft® .NET Framework");\n</code></pre>\n\n<p>I\'m using this technique to group assemblies by product under the About screen of the application and it seems to work just fine for me.</p>\n'}, {'answer_id': 3666403, 'author': 'Johannes Rudolph', 'author_id': 125407, 'author_profile': 'https://Stackoverflow.com/users/125407', 'pm_score': 2, 'selected': False, 'text': '<p>I have had to deal with the exact same issue. Unfortunately, all answers given so far are <strong>insufficient</strong> to safely determine if an assembly is part of the .NET Framework.</p>\n\n<p>Microsoft puts a class named <code>FXAssembly</code> into the global namespace of each framework assembly with a const string indicating the version:</p>\n\n<pre><code>.class private abstract auto ansi sealed beforefieldinit FXAssembly\n    extends [mscorlib]System.Object\n{\n    .field assembly static literal string Version = string(\'2.0.0.0\')\n\n}\n</code></pre>\n\n<p>Use this "marker" to check if an assembly is a framework assembly. Checking the public key too won\'t hurt either.</p>\n'}, {'answer_id': 14558666, 'author': 'Jean Hominal', 'author_id': 113158, 'author_profile': 'https://Stackoverflow.com/users/113158', 'pm_score': 2, 'selected': False, 'text': "<p>When you install Visual Studio, you get the reference assemblies in various subfolders of the form <code>C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\{FrameworkName}\\{FrameworkVersion}</code> - the most interesting thing could be the <code>RedistList\\FrameworkList.xml</code> file that contains a list of all assembly names that were shipped with the given framework version.</p>\n\n<p>E.g. <code>C:\\Program Files (x86)\\Reference Assemblies\\Microsoft\\Framework\\.NETFramework\\v4.0\\RedistList\\FrameworkList.xml</code> seems to contain a list of all of .NET 4.0's Framework assemblies.</p>\n\n<p>You could easily use these files to establish static white lists of assemblies.</p>\n"}]
['https://Stackoverflow.com/questions/52134', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4002/']