public AssemblyDelaySignAttributeTest()
        {
            //create a dynamic assembly with the required attribute
            //and check for the validity

            dynAsmName.Name = "TestAssembly";

            dynAssembly = Thread.GetDomain().DefineDynamicAssembly(
                dynAsmName, AssemblyBuilderAccess.Run
                );

            // Set the required Attribute of the assembly.
            Type            attribute = typeof(AssemblyDelaySignAttribute);
            ConstructorInfo ctrInfo   = attribute.GetConstructor(
                new Type [] { typeof(bool) }
                );
            CustomAttributeBuilder attrBuilder =
                new CustomAttributeBuilder(ctrInfo, new object [1] {
                false
            });

            dynAssembly.SetCustomAttribute(attrBuilder);
            object [] attributes = dynAssembly.GetCustomAttributes(true);
            attr = attributes [0] as AssemblyDelaySignAttribute;
        }
    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify property DelaySign .");

        try
        {
            bool delaySign = false;
            AssemblyDelaySignAttribute adsa = new AssemblyDelaySignAttribute(delaySign);

            if (adsa.DelaySign != delaySign)
            {
                TestLibrary.TestFramework.LogError("002.1", "Property DelaySign Err.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return retVal;
    }
示例#3
0
    public bool PosTest2()
    {
        bool retVal = true;

        // Add your scenario description here
        TestLibrary.TestFramework.BeginScenario("PosTest2: Verify property DelaySign .");

        try
        {
            bool delaySign = false;
            AssemblyDelaySignAttribute adsa = new AssemblyDelaySignAttribute(delaySign);

            if (adsa.DelaySign != delaySign)
            {
                TestLibrary.TestFramework.LogError("002.1", "Property DelaySign Err.");
                retVal = false;
            }
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002.2", "Unexpected exception: " + e);
            TestLibrary.TestFramework.LogInformation(e.StackTrace);
            retVal = false;
        }

        return(retVal);
    }
示例#4
0
        public static void AssemblyDelaySignAttributeTests()
        {
            var attr1 = new AssemblyDelaySignAttribute(false);

            Assert.False(attr1.DelaySign);

            var attr2 = new AssemblyDelaySignAttribute(true);

            Assert.True(attr2.DelaySign);
        }
        public void CtorTest()
        {
            var a = new AssemblyDelaySignAttribute(true);

            Assert.AreEqual(true, a.DelaySign);
        }
示例#6
0
        public void Ctor_Bool(bool delaySign)
        {
            var attribute = new AssemblyDelaySignAttribute(delaySign);

            Assert.Equal(delaySign, attribute.DelaySign);
        }
        private void DoIt()
        {
            AssemblyName aname = new AssemblyName();

            aname.Name = Path.GetFileNameWithoutExtension(outFile);
            if (culture != null)
            {
                aname.CultureInfo = new CultureInfo(culture);
            }

            string fileName = Path.GetFileName(outFile);

            AssemblyBuilder ab;

            /*
             * Emit Manifest
             * */

            if (isTemplateFile)
            {
                // LAMESPEC: according to MSDN, the template assembly must have a
                // strong name but this is not enforced
                Assembly assembly = Assembly.LoadFrom(templateFile);

                // inherit signing related settings from template, but do not
                // override command-line options
                object [] attrs = assembly.GetCustomAttributes(true);
                foreach (object o in attrs)
                {
                    if (o is AssemblyKeyFileAttribute)
                    {
                        if (keyfile != null)
                        {
                            // ignore if specified on command line
                            continue;
                        }
                        AssemblyKeyFileAttribute keyFileAttr = (AssemblyKeyFileAttribute)o;
                        // ignore null or zero-length keyfile
                        if (keyFileAttr.KeyFile == null || keyFileAttr.KeyFile.Length == 0)
                        {
                            continue;
                        }
                        keyfile = Path.Combine(Path.GetDirectoryName(templateFile),
                                               keyFileAttr.KeyFile);
                    }
                    else if (o is AssemblyDelaySignAttribute)
                    {
                        if (delaysign != DelaySign.NotSet)
                        {
                            // ignore if specified on command line
                            continue;
                        }
                        AssemblyDelaySignAttribute delaySignAttr = (AssemblyDelaySignAttribute)o;
                        delaysign = delaySignAttr.DelaySign ? DelaySign.Yes :
                                    DelaySign.No;
                    }
                    else if (o is AssemblyKeyNameAttribute)
                    {
                        if (keyname != null)
                        {
                            // ignore if specified on command line
                            continue;
                        }
                        AssemblyKeyNameAttribute keynameAttr = (AssemblyKeyNameAttribute)o;
                        // ignore null or zero-length keyname
                        if (keynameAttr.KeyName == null || keynameAttr.KeyName.Length == 0)
                        {
                            continue;
                        }
                        keyname = keynameAttr.KeyName;
                    }
                }
                aname.Version       = assembly.GetName().Version;
                aname.HashAlgorithm = assembly.GetName().HashAlgorithm;
            }

            SetKeyPair(aname);

            if (fileName != outFile)
            {
                ab = AppDomain.CurrentDomain.DefineDynamicAssembly(aname, AssemblyBuilderAccess.Save, Path.GetDirectoryName(outFile));
            }
            else
            {
                ab = AppDomain.CurrentDomain.DefineDynamicAssembly(aname, AssemblyBuilderAccess.Save);
            }

            foreach (CustomAttributeBuilder cb in cattrs)
            {
                ab.SetCustomAttribute(cb);
            }

            /*
             * Emit modules
             */

            foreach (ModuleInfo mod in inputFiles)
            {
                MethodInfo mi = typeof(AssemblyBuilder).GetMethod("AddModule", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (mi == null)
                {
                    Report(0, "Cannot add modules on this runtime: try the Mono runtime instead.");
                }

                if (mod.target != null)
                {
                    File.Copy(mod.fileName, mod.target, true);
                    mod.fileName = mod.target;
                }

                bool isAssembly = false;
                try
                {
                    AssemblyName.GetAssemblyName(mod.fileName);
                    isAssembly = true;
                }
                catch (Exception)
                {
                }

                if (isAssembly)
                {
                    ReportWarning(1020, "Ignoring included assembly '" + mod.fileName + "'");
                }
                else
                {
                    mi.Invoke(ab, new object [] { mod.fileName });
                }
            }

            /*
             * Set entry point
             */

            if (entryPoint != null)
            {
                string mainClass  = entryPoint.Substring(0, entryPoint.LastIndexOf('.'));
                string mainMethod = entryPoint.Substring(entryPoint.LastIndexOf('.') + 1);

                MethodInfo mainMethodInfo = null;

                try
                {
                    Type mainType = ab.GetType(mainClass);
                    if (mainType != null)
                    {
                        mainMethodInfo = mainType.GetMethod(mainMethod);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                if (mainMethodInfo != null)
                {
                    ab.SetEntryPoint(mainMethodInfo);
                }
                else
                {
                    Report(1037, "Unable to find the entry point method '" + entryPoint + "'");
                }
            }

            /*
             * Emit resources
             */

            ab.DefineVersionInfoResource();

            if (win32IconFile != null)
            {
                try
                {
                    MethodInfo mi = typeof(AssemblyBuilder).GetMethod("DefineIconResource", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                    if (mi == null)
                    {
                        Report(0, "Cannot embed win32 icons on this runtime: try the Mono runtime instead.");
                    }
                    mi.Invoke(ab, new object [] { win32IconFile });
                }
                catch (Exception ex)
                {
                    Report(1031, "Error reading icon '" + win32IconFile + "' --" + ex);
                }
            }

            if (win32ResFile != null)
            {
                try
                {
                    ab.DefineUnmanagedResource(win32ResFile);
                }
                catch (Exception ex)
                {
                    Report(1019, "Metadata failure creating assembly -- " + ex);
                }
            }

            foreach (ResourceInfo res in resources)
            {
                if (res.name == null)
                {
                    res.name = Path.GetFileName(res.fileName);
                }

                foreach (ResourceInfo res2 in resources)
                {
                    if ((res != res2) && (res.name == res2.name))
                    {
                        Report(1046, String.Format("Resource identifier '{0}' has already been used in this assembly", res.name));
                    }
                }

                if (res.isEmbedded)
                {
                    MethodInfo mi = typeof(AssemblyBuilder).GetMethod("EmbedResourceFile", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic,
                                                                      null, CallingConventions.Any, new Type [] { typeof(string), typeof(string) }, null);
                    if (mi == null)
                    {
                        Report(0, "Cannot embed resources on this runtime: try the Mono runtime instead.");
                    }
                    mi.Invoke(ab, new object [] { res.name, res.fileName });
                }
                else
                {
                    if (res.target != null)
                    {
                        File.Copy(res.fileName, res.target, true);
                        res.fileName = res.target;
                    }

                    ab.AddResourceFile(res.name, res.fileName,
                                       res.isPrivate ? ResourceAttributes.Private : ResourceAttributes.Public);
                }
            }

            try
            {
                ab.Save(fileName);
            }
            catch (Exception ex)
            {
                Report(1019, "Metadata failure creating assembly -- " + ex);
            }
        }