Determining if an assembly is part of the .NET fra

2019-03-18 02:51发布

How can I tell from the assembly name, or assembly class (or others like it), whether an assembly is part of the .NET framework (that is, System.windows.Forms)?

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

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.

The ultimate solution would be that there is an IsFramework property... :)

7条回答
时光不老,我们不散
2楼-- · 2019-03-18 03:53

No, it doesn't begin with "System". You could check "WindowsBase" which is a framework assembly.

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).

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 (RedistList\FrameworkList.xml).

FrameworkList.xml can be found in:

  • .NET 2.0: C:\Windows\Microsoft.NET\Framework64\v2.0.50727\RedistList
  • .NET 3.x: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\vVersionNumber\RedistList
  • .NET 4.x: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\vVersionNumber\RedistList
  • .NET Core: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\vVersionNumber\RedistList
查看更多
登录 后发表回答