@manhng

Welcome to my blog!

Assembly tools

May 31, 2021 11:54

Assembly tools (edit)

https://manhng.com/blog/reflection-load-all-classes-properties-constructors/

https://manhng.com/blog/get-all-assemblies/

https://manhng.com/blog/reflection/

https://manhng.com/blog/decompiler/

https://manhng.com/blog/applied-microsoft-net-framework-programming/

https://manhng.com/blog/benchmarking-with-stopwatch/

Code

using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;

string[] pathToDLLs = System.IO.Directory.GetFiles(folderPath, "*.dll", SearchOption.AllDirectories);

string reportFolderPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory), "Report");

File.WriteAllText(Path.Combine(reportFolderPath, "DEF.txt"), sb.ToString(), Encoding.UTF8);
File.WriteAllText(Path.Combine(reportFolderPath, $"DEF_{DateTime.Now.ToString("yyyyMMddHHmmm")}.txt"), sb.ToString(), Encoding.UTF8);

Process.Start(@"C:\Program Files\Notepad++\notepad++.exe", Path.Combine(reportFolderPath, "DEF.txt"));

//ProductName: System.Reflection.AssemblyProductAttribute
//ProductVersion: System.Reflection.AssemblyInformationalVersionAttribute

//FileDescription: System.Reflection.AssemblyTitleAttribute
//FileVersion: System.Reflection.AssemblyVersionAttribute

//System.Resources.ResourceManager
//System.Reflection.AssemblyCultureAttribute

//Add references (*.dll) to the project automatically ( programmatically )
const string ReferenceInclude = "<Reference Include=\"{0}\"><HintPath>{1}</HintPath></Reference>";
foreach (string pathToDLL in Directory.GetFiles(folderPath, "*.dll"))
{
Assembly assembly = Assembly.LoadFile(pathToDLL);
string nameSpace = assembly.GetName().Name;

Type aType = assembly.GetType($"{nameSpace}.{className}");
}

foreach (string dll in Directory.GetFiles(folderPath, "*.dll"))
{
if (!string.IsNullOrWhiteSpace(dll))
{
string fileNameWithOutExtension = Path.GetFileNameWithoutExtension(dll);
sb.AppendLine(string.Format(ReferenceInclude, fileNameWithOutExtension, dll));

//if (fileNameWithOutExtension.StartsWith("MyNamespace") && !fileNameWithOutExtension.EndsWith(".cs"))
//{
// sb.AppendLine(string.Format(ReferenceInclude, fileNameWithOutExtension, dll));
//}
}
}

Categories

Recent posts