コード例 #1
0
        private static Assembly ResolveAssembly(object sender, ResolveEventArgs args)
        {
            if ( args.Name.StartsWith( "Corvalius.ArraySlice.Portable" ))
            {
                var projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\AssemblyToProcess\AssemblyToProcess.csproj"));
                var assemblyPath = Path.Combine(Path.GetDirectoryName(projectPath), @"bin\Debug\AssemblyToProcess.dll");
            #if (!DEBUG)
                assemblyPath = assemblyPath.Replace("Debug", "Release");
            #endif

                var newAssemblyPath = assemblyPath.Replace(".dll", "2.dll");
                File.Copy(assemblyPath, newAssemblyPath, true);

                var moduleDefinition = ModuleDefinition.ReadModule(newAssemblyPath);
                var weaver = new ModuleWeaver
                {
                    ModuleDefinition = moduleDefinition,
                    AssemblyResolver = new MockAssemblyResolver()
                };

                weaver.Execute();
                moduleDefinition.Write(newAssemblyPath);

                return Assembly.LoadFile(newAssemblyPath);
            }

            return null;
        }
コード例 #2
0
ファイル: WeaverBase.cs プロジェクト: mdabbagh88/arrayslice
        public WeaverBase()
        {
            var projectPath = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, @"..\..\..\AssemblyToProcess\AssemblyToProcess.csproj"));

            AssemblyPath = Path.Combine(Path.GetDirectoryName(projectPath), @"bin\Debug\AssemblyToProcess.dll");
            #if (!DEBUG)
            AssemblyPath = AssemblyPath.Replace("Debug", "Release");
            #endif

            NewAssemblyPath = AssemblyPath.Replace(".dll", rnd.Next() + ".dll");
            File.Copy(AssemblyPath, NewAssemblyPath, true);

            var moduleDefinition = ModuleDefinition.ReadModule(NewAssemblyPath);
            Weaver = new ModuleWeaver
            {
                ModuleDefinition = moduleDefinition,
                AssemblyResolver = new MockAssemblyResolver()
            };

            Weaver.Execute();
            moduleDefinition.Write(NewAssemblyPath);

            Assembly = Assembly.LoadFile(NewAssemblyPath);
        }