diff options
author | Kenneth Skovhede <kenneth@hexad.dk> | 2016-04-23 14:10:54 +0300 |
---|---|---|
committer | Kenneth Skovhede <kenneth@hexad.dk> | 2016-04-23 14:10:54 +0300 |
commit | f652c4e8decb97a3d79dd35e10833ec005337623 (patch) | |
tree | d44e0161cdc78b2fadbcc8200a68d735a90ff5fa /BuildTools | |
parent | 96d2d935b0239c8704df6151ea101febc5b918cd (diff) |
Added DependencyFinder tool
Diffstat (limited to 'BuildTools')
-rw-r--r-- | BuildTools/DependencyFinder/DependencyFinder.csproj | 56 | ||||
-rw-r--r-- | BuildTools/DependencyFinder/DependencyFinder.sln | 17 | ||||
-rw-r--r-- | BuildTools/DependencyFinder/Program.cs | 64 | ||||
-rw-r--r-- | BuildTools/DependencyFinder/Properties/AssemblyInfo.cs | 27 | ||||
-rw-r--r-- | BuildTools/DependencyFinder/packages.config | 4 |
5 files changed, 168 insertions, 0 deletions
diff --git a/BuildTools/DependencyFinder/DependencyFinder.csproj b/BuildTools/DependencyFinder/DependencyFinder.csproj new file mode 100644 index 000000000..db9645ffb --- /dev/null +++ b/BuildTools/DependencyFinder/DependencyFinder.csproj @@ -0,0 +1,56 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">x86</Platform> + <ProjectGuid>{3E891818-579A-4C06-8066-4C702BFA5921}</ProjectGuid> + <OutputType>Exe</OutputType> + <RootNamespace>DependencyFinder</RootNamespace> + <AssemblyName>DependencyFinder</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' "> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug</OutputPath> + <DefineConstants>DEBUG;</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <PlatformTarget>x86</PlatformTarget> + <ConsolePause>false</ConsolePause> + <Commandlineparameters>../../../../Duplicati/GUI/Duplicati.GUI.TrayIcon/bin/Debug</Commandlineparameters> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' "> + <DebugType>full</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release</OutputPath> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Externalconsole>true</Externalconsole> + <PlatformTarget>x86</PlatformTarget> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="Mono.Cecil"> + <HintPath>packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll</HintPath> + </Reference> + <Reference Include="Mono.Cecil.Mdb"> + <HintPath>packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll</HintPath> + </Reference> + <Reference Include="Mono.Cecil.Pdb"> + <HintPath>packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll</HintPath> + </Reference> + <Reference Include="Mono.Cecil.Rocks"> + <HintPath>packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll</HintPath> + </Reference> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> + <ItemGroup> + <None Include="packages.config" /> + </ItemGroup> +</Project>
\ No newline at end of file diff --git a/BuildTools/DependencyFinder/DependencyFinder.sln b/BuildTools/DependencyFinder/DependencyFinder.sln new file mode 100644 index 000000000..cd8aea67c --- /dev/null +++ b/BuildTools/DependencyFinder/DependencyFinder.sln @@ -0,0 +1,17 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 2012
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DependencyFinder", "DependencyFinder.csproj", "{3E891818-579A-4C06-8066-4C702BFA5921}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {3E891818-579A-4C06-8066-4C702BFA5921}.Debug|x86.ActiveCfg = Debug|x86
+ {3E891818-579A-4C06-8066-4C702BFA5921}.Debug|x86.Build.0 = Debug|x86
+ {3E891818-579A-4C06-8066-4C702BFA5921}.Release|x86.ActiveCfg = Release|x86
+ {3E891818-579A-4C06-8066-4C702BFA5921}.Release|x86.Build.0 = Release|x86
+ EndGlobalSection
+EndGlobal
diff --git a/BuildTools/DependencyFinder/Program.cs b/BuildTools/DependencyFinder/Program.cs new file mode 100644 index 000000000..e819cac0b --- /dev/null +++ b/BuildTools/DependencyFinder/Program.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using Mono.Cecil; +using System.IO; +using System.Linq; + +namespace DependencyFinder +{ + class MainClass + { + public static void Main(string[] args) + { + var lst = + Directory.EnumerateFiles(args[0], "*.exe", SearchOption.AllDirectories).Union( + Directory.EnumerateFiles(args[0], "*.dll", SearchOption.AllDirectories)) + .Select(x => { + try { return AssemblyDefinition.ReadAssembly(x); } + catch { return null; } + }).Where(x => x != null) + .Distinct(); + + PoC(lst, Console.Out, new [] { args[0] }); + + } + + //Adapted from: https://stackoverflow.com/questions/9262464/tool-to-show-assembly-dependencies + public static void PoC(IEnumerable<AssemblyDefinition> assemblies, TextWriter writer, IEnumerable<string> searchfolders) + { + var resolver = new DefaultAssemblyResolver(); + searchfolders.ToList().ForEach(x => resolver.AddSearchDirectory(x)); + + //writer.WriteLine("digraph Dependencies {"); + var loaded = assemblies + .SelectMany(a => a.Modules.Cast<ModuleDefinition>()) + .SelectMany(m => m.AssemblyReferences.Cast<AssemblyNameReference>()) + .Distinct() + .Select(asm => { + var dllname = asm.Name + ".dll"; + //Console.WriteLine("Probing for {0}", dllname); + try { return AssemblyDefinition.ReadAssembly(dllname); } + catch { } + try { return resolver.Resolve(asm.FullName); } + catch { } + + return null; + }) + .Where(assembly => assembly != null) + .ToList(); + + //loaded.ForEach(a => a.MainModule.ReadSymbols()); + + loaded.Select(x => x.FullName).Distinct().OrderBy(x => x).ToList().ForEach(x => writer.WriteLine("{0}", x)); + /*loaded.ForEach(a => + { + foreach (var r in a.MainModule.AssemblyReferences.Cast<AssemblyNameReference>()) + writer.WriteLine(@"""{0}"" -> ""{1}"";", r.Name, a.Name.Name); + } );*/ + + //writer.WriteLine("}"); + } + + + } +} diff --git a/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs b/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..637ec8aad --- /dev/null +++ b/BuildTools/DependencyFinder/Properties/AssemblyInfo.cs @@ -0,0 +1,27 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("DependencyFinder")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("kenneth")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/BuildTools/DependencyFinder/packages.config b/BuildTools/DependencyFinder/packages.config new file mode 100644 index 000000000..e304cab94 --- /dev/null +++ b/BuildTools/DependencyFinder/packages.config @@ -0,0 +1,4 @@ +<?xml version="1.0" encoding="utf-8"?> +<packages> + <package id="Mono.Cecil" version="0.9.6.1" targetFramework="net45" /> +</packages>
\ No newline at end of file |