예제 #1
0
        public static ModuleDefinition WeaveTestTarget(
            string targetAssemblyFilename,
            XElement config)
        {
            Contract.Requires(config != null);
            Contract.Ensures(Contract.Result <ModuleDefinition>() != null);

            var moduleWeaver = ModuleWeaverHelper.GetModuleWeaver(targetAssemblyFilename, config);

            moduleWeaver.Execute();

            var tempProcessedAssemblyPath = Path.Combine(Path.GetDirectoryName(moduleWeaver.AssemblyFilePath), string.Format("{0}.dll", Path.GetRandomFileName()));

            try
            {
                moduleWeaver.ModuleDefinition.Write(tempProcessedAssemblyPath);
            }
            finally
            {
                if (File.Exists(tempProcessedAssemblyPath))
                {
                    try
                    {
                        File.Delete(tempProcessedAssemblyPath);
                    }
                    catch { /* Best-effort deletion only */ }
                }
            }

            return(moduleWeaver.ModuleDefinition);
        }
예제 #2
0
        public static byte[] GetRawWeavedAssembly(
            string targetAssemblyFilename,
            XElement config)
        {
            Contract.Requires(config != null);
            Contract.Ensures(Contract.Result <byte[]>() != null);

            using (var memoryStream = new MemoryStream())
            {
                ModuleWeaverHelper.WeaveTestTarget(targetAssemblyFilename, config).Write(memoryStream);
                return(memoryStream.GetBuffer());
            }
        }
예제 #3
0
        public static Assembly WeaveAndLoadTestTarget(
            string targetAssemblyFilename,
            CiladorConfigType config,
            params Tuple <string, string>[] fodyWeaverTaskProperties)
        {
            Contract.Requires(config != null);
            Contract.Ensures(Contract.Result <Assembly>() != null);

            var mixedAssembly = AppDomain.CurrentDomain.Load(ModuleWeaverHelper.GetRawWeavedAssembly(
                                                                 targetAssemblyFilename,
                                                                 ModuleWeaverHelper.BuildXElementConfig(config, fodyWeaverTaskProperties)));

            return(mixedAssembly);
        }
예제 #4
0
        public static ModuleDefinition WeaveTestTarget(
            string targetAssemblyFilename,
            XElement config)
        {
            Contract.Requires(config != null);
            Contract.Ensures(Contract.Result <ModuleDefinition>() != null);

            var moduleWeaver = ModuleWeaverHelper.GetModuleWeaver(targetAssemblyFilename, config);

            bool   isVerified;
            string verificationOutput;

            AssemblyVerifier.RunVerifyProcessAndCollectOutput(moduleWeaver.AssemblyFilePath, out isVerified, out verificationOutput);
            Assert.That(isVerified, string.Format("Unprocessed assembly could not be verified: \n{0}", verificationOutput));

            moduleWeaver.Execute();

            var tempProcessedAssemblyPath = Path.Combine(Path.GetDirectoryName(moduleWeaver.AssemblyFilePath), string.Format("{0}.dll", Path.GetRandomFileName()));

            try
            {
                moduleWeaver.ModuleDefinition.Write(tempProcessedAssemblyPath);
                AssemblyVerifier.RunVerifyProcessAndCollectOutput(tempProcessedAssemblyPath, out isVerified, out verificationOutput);
                Assert.That(isVerified, string.Format("Processed assembly could not be verified: \n{0}", verificationOutput));
            }
            finally
            {
                if (File.Exists(tempProcessedAssemblyPath))
                {
                    try
                    {
                        File.Delete(tempProcessedAssemblyPath);
                    }
                    catch { /* Best-effort deletion only */ }
                }
            }

            return(moduleWeaver.ModuleDefinition);
        }