コード例 #1
0
        public AppConfigManipulator()
        {
            XDocument doc;
            if (File.Exists(_oldConfigFilename))
                doc = XDocument.Load(_oldConfigFilename);
            else
                doc = XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<startup><supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v4.5""/></startup></configuration>");

            {
                var configuration = doc.Root;
                if (configuration != null)
                {
                    var runtime = configuration.Element("runtime");
                    if (runtime == null)
                        configuration.Add(runtime = new XElement("runtime"));
                    var nameAssemblyBinding = Namespace + "assemblyBinding";

                    var assemblyBinding = runtime.Element(nameAssemblyBinding);
                    if (assemblyBinding == null)
                        runtime.Add(assemblyBinding = new XElement(nameAssemblyBinding));
                    // assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
                    var an = typeof(PhpDummy).Assembly.GetName();
                    var pk = Bcd(an.GetPublicKeyToken());
                    var dependentAssembly = (from da in assemblyBinding.Elements(Namespace + "dependentAssembly")
                                             let tmp = DependentAssemblyWrapper.Parse(da)
                                             where tmp != null
                                             where tmp.Name == an.Name
                                             select tmp).FirstOrDefault();

                    if (dependentAssembly == null)
                    {
                        dependentAssembly = new DependentAssemblyWrapper
                        {
                            Name = an.Name,
                            PublicKeyToken = pk,
                        };
                        dependentAssembly.Update();
                        assemblyBinding.Add(dependentAssembly.DependentAssemblyElement);
                    }


                    dependentAssembly.RedirectOldVersion = "1.0.0.0-" + an.Version;
                    dependentAssembly.RedirectNewVersion = an.Version.ToString();
                    dependentAssembly.Update();
                }
            }

            path = string.Format("app{0:N}.config", Guid.NewGuid());
            path = Path.Combine(Path.GetTempPath(), path);
            doc.Save(path);
            AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
            ResetConfigMechanism();
        }
コード例 #2
0
            // Public Methods 

            public static DependentAssemblyWrapper Parse(XElement dependentAssembly)
            {
                var assemblyIdentity = dependentAssembly.Element(Namespace + "assemblyIdentity");

                if (assemblyIdentity == null)
                {
                    return(null);
                }
                var x = new DependentAssemblyWrapper
                {
                    DependentAssemblyElement = dependentAssembly,
                    Name           = (string)assemblyIdentity.Attribute("name"),
                    PublicKeyToken = (string)assemblyIdentity.Attribute("publicKeyToken"),
                    Culture        = (string)assemblyIdentity.Attribute("culture")
                };

                return(x);
            }
コード例 #3
0
            // Public Methods 

            public static DependentAssemblyWrapper Parse(XElement dependentAssembly)
            {
                var assemblyIdentity = dependentAssembly.Element(Namespace + "assemblyIdentity");
                if (assemblyIdentity == null)
                    return null;
                var x = new DependentAssemblyWrapper
                {
                    DependentAssemblyElement = dependentAssembly,
                    Name = (string)assemblyIdentity.Attribute("name"),
                    PublicKeyToken = (string)assemblyIdentity.Attribute("publicKeyToken"),
                    Culture = (string)assemblyIdentity.Attribute("culture")
                };
                return x;
            }
コード例 #4
0
        public AppConfigManipulator()
        {
            XDocument doc;

            if (File.Exists(_oldConfigFilename))
            {
                doc = XDocument.Load(_oldConfigFilename);
            }
            else
            {
                doc = XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
<startup><supportedRuntime version=""v4.0"" sku="".NETFramework,Version=v4.5""/></startup></configuration>");
            }

            {
                var configuration = doc.Root;
                if (configuration != null)
                {
                    var runtime = configuration.Element("runtime");
                    if (runtime == null)
                    {
                        configuration.Add(runtime = new XElement("runtime"));
                    }
                    var nameAssemblyBinding = Namespace + "assemblyBinding";

                    var assemblyBinding = runtime.Element(nameAssemblyBinding);
                    if (assemblyBinding == null)
                    {
                        runtime.Add(assemblyBinding = new XElement(nameAssemblyBinding));
                    }
                    // assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"
                    var an = typeof(Py).Assembly.GetName();
                    var pk = Bcd(an.GetPublicKeyToken());
                    var dependentAssembly = (from da in assemblyBinding.Elements(Namespace + "dependentAssembly")
                                             let tmp = DependentAssemblyWrapper.Parse(da)
                                                       where tmp != null
                                                       where tmp.Name == an.Name
                                                       select tmp).FirstOrDefault();

                    if (dependentAssembly == null)
                    {
                        dependentAssembly = new DependentAssemblyWrapper
                        {
                            Name           = an.Name,
                            PublicKeyToken = pk,
                        };
                        dependentAssembly.Update();
                        assemblyBinding.Add(dependentAssembly.DependentAssemblyElement);
                    }


                    dependentAssembly.RedirectOldVersion = "1.0.0.0-" + an.Version;
                    dependentAssembly.RedirectNewVersion = an.Version.ToString();
                    dependentAssembly.Update();
                }
            }

            path = string.Format("app{0:N}.config", Guid.NewGuid());
            path = Path.Combine(Path.GetTempPath(), path);
            doc.Save(path);
            AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
            ResetConfigMechanism();
        }