Exemplo n.º 1
0
        BuildResult GenerateManifest(IProgressMonitor monitor, MoonlightProject proj, DotNetProjectConfiguration conf, ConfigurationSelector slnConf)
        {
            const string depNS = "http://schemas.microsoft.com/client/2007/deployment";

            monitor.Log.WriteLine("Generating manifest...");

            var res      = new BuildResult();
            var manifest = conf.OutputDirectory.Combine("AppManifest.xaml");

            string template = String.IsNullOrEmpty(proj.SilverlightManifestTemplate)?
                              null : proj.GetAbsoluteChildPath(proj.SilverlightManifestTemplate);

            XmlDocument doc = new XmlDocument();

            if (template != null)
            {
                if (!File.Exists(template))
                {
                    monitor.ReportError("Could not find manifest template '" + template + "'.", null);
                    res.AddError("Could not find manifest template '" + template + "'.");
                    res.FailedBuildCount++;
                    return(res);
                }
                try {
                    doc.Load(template);
                } catch (XmlException ex) {
                    monitor.ReportError("Could not load manifest template '" + template + "'.", null);
                    res.AddError(template, ex.LineNumber, ex.LinePosition, null, "Error loading manifest template '" + ex.Source);
                    res.FailedBuildCount++;
                    return(res);
                } catch (Exception ex) {
                    monitor.ReportError("Could not load manifest template '" + template + "'.", ex);
                    res.AddError("Could not load manifest template '" + template + "': " + ex.ToString());
                    res.FailedBuildCount++;
                    return(res);
                }
            }
            else
            {
                doc.LoadXml(@"<Deployment xmlns=""http://schemas.microsoft.com/client/2007/deployment"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""></Deployment>");
            }

            try {
                XmlNode deploymentNode = doc.DocumentElement;
                if (deploymentNode == null || deploymentNode.Name != "Deployment" || deploymentNode.NamespaceURI != depNS)
                {
                    monitor.ReportError("Missing or invalid root <Deployment> element in manifest template '" + template + "'.", null);
                    res.AddError("Missing root <Deployment> element in manifest template '" + template + "'.");
                    res.FailedBuildCount++;
                    return(res);
                }
                if (deploymentNode.Attributes["EntryPointAssembly"] == null)
                {
                    deploymentNode.Attributes.Append(doc.CreateAttribute("EntryPointAssembly")).Value = conf.CompiledOutputName.FileNameWithoutExtension;
                }
                if (!String.IsNullOrEmpty(proj.SilverlightAppEntry) && deploymentNode.Attributes["EntryPointType"] == null)
                {
                    deploymentNode.Attributes.Append(doc.CreateAttribute("EntryPointType")).Value = proj.SilverlightAppEntry;
                }

                if (deploymentNode.Attributes["RuntimeVersion"] == null)
                {
                    string runtimeVersion = null;
                    string fxVersion      = proj.TargetFramework.Id.Version;

                    if (proj.TargetRuntime is MonoDevelop.Core.Assemblies.MonoTargetRuntime)
                    {
                        var package = proj.TargetRuntime.RuntimeAssemblyContext.GetPackage("moonlight-web-" + fxVersion);
                        if (package != null && package.IsFrameworkPackage)
                        {
                            runtimeVersion = package.Version;
                        }
                        else
                        {
                            LoggingService.LogWarning("Moonlight core framework package not found, cannot determine " +
                                                      "runtime version string. Falling back to default value.");
                        }
                    }

                    if (runtimeVersion == null)
                    {
                        //FIXME how will we determine this for other runtimes?
                        runtimeVersion = "2.0.31005.0";
                    }

                    deploymentNode.Attributes.Append(doc.CreateAttribute("RuntimeVersion")).Value = runtimeVersion;
                }

                XmlNamespaceManager mgr = new XmlNamespaceManager(doc.NameTable);
                mgr.AddNamespace("dep", depNS);
                XmlNode partsNode = deploymentNode.SelectSingleNode("dep:Deployment.Parts", mgr);
                if (partsNode == null)
                {
                    partsNode = deploymentNode.AppendChild(doc.CreateElement("Deployment.Parts", depNS));
                }

                AddAssemblyPart(doc, partsNode, conf.CompiledOutputName);
                foreach (ProjectReference pr in proj.References)
                {
                    if (pr.LocalCopy)
                    {
                        var pk = pr.Package;
                        if (pk == null || !pk.IsFrameworkPackage || pk.Name.EndsWith("-redist"))
                        {
                            foreach (string s in pr.GetReferencedFileNames(slnConf))
                            {
                                AddAssemblyPart(doc, partsNode, s);
                            }
                        }
                    }
                }
            } catch (XmlException ex) {
                monitor.ReportError("Error processing manifest template.", ex);
                res.AddError(template, ex.LineNumber, ex.LinePosition, null, "Error processing manifest template: '" + ex.Source);
                res.FailedBuildCount++;
                return(res);
            }

            doc.Save(manifest);

            return(res);
        }
		BuildResult GenerateManifest (IProgressMonitor monitor, MoonlightProject proj, DotNetProjectConfiguration conf, ConfigurationSelector slnConf)
		{
			const string depNS = "http://schemas.microsoft.com/client/2007/deployment";
			
			monitor.Log.WriteLine ("Generating manifest...");
			
			var res = new BuildResult ();
			var manifest = conf.OutputDirectory.Combine ("AppManifest.xaml");

			string template = String.IsNullOrEmpty (proj.SilverlightManifestTemplate)?
				null : proj.GetAbsoluteChildPath (proj.SilverlightManifestTemplate);

			XmlDocument doc = new XmlDocument ();
			if (template != null) {
				if (!File.Exists (template)) {
					monitor.ReportError ("Could not find manifest template '" +  template + "'.", null);
					res.AddError ("Could not find manifest template '" +  template + "'.");
					res.FailedBuildCount++;
					return res;
				}
				try {
					doc.Load (template);
				} catch (XmlException ex) {
					monitor.ReportError ("Could not load manifest template '" +  template + "'.", null);
					res.AddError (template, ex.LineNumber, ex.LinePosition, null, "Error loading manifest template '" + ex.Source);
					res.FailedBuildCount++;
					return res;
				} catch (Exception ex) {
					monitor.ReportError ("Could not load manifest template '" +  template + "'.", ex);
					res.AddError ("Could not load manifest template '" +  template + "': " + ex.ToString ());
					res.FailedBuildCount++;
					return res;
				}

			} else {
				doc.LoadXml (@"<Deployment xmlns=""http://schemas.microsoft.com/client/2007/deployment"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""></Deployment>");
			}
			
			try {
				XmlNode deploymentNode = doc.DocumentElement;
				if (deploymentNode == null || deploymentNode.Name != "Deployment" || deploymentNode.NamespaceURI != depNS) {
					monitor.ReportError ("Missing or invalid root <Deployment> element in manifest template '" +  template + "'.", null);
					res.AddError ("Missing root <Deployment> element in manifest template '" +  template + "'.");
					res.FailedBuildCount++;
					return res;
				}
				if (deploymentNode.Attributes["EntryPointAssembly"] == null)
					deploymentNode.Attributes.Append (doc.CreateAttribute ("EntryPointAssembly")).Value = conf.CompiledOutputName.FileNameWithoutExtension;
				if (!String.IsNullOrEmpty (proj.SilverlightAppEntry) && deploymentNode.Attributes["EntryPointType"] == null)
					deploymentNode.Attributes.Append (doc.CreateAttribute ("EntryPointType")).Value = proj.SilverlightAppEntry;

				if (deploymentNode.Attributes["RuntimeVersion"] == null) {
					string runtimeVersion = null;
					string fxVersion = MoonlightFrameworkBackend.GetFxVersion (proj.TargetFramework);
					
					if (proj.TargetRuntime is MonoDevelop.Core.Assemblies.MonoTargetRuntime) {
						var package = proj.TargetRuntime.RuntimeAssemblyContext.GetPackage ("moonlight-web-" + fxVersion);
						if (package != null && package.IsFrameworkPackage) {
							runtimeVersion = package.Version;
						} else {
							LoggingService.LogWarning ("Moonlight core framework package not found, cannot determine " +
								"runtime version string. Falling back to default value.");
						}
					}
					
					if (runtimeVersion == null) {
						//FIXME how will we determine this for other runtimes?
						runtimeVersion = "2.0.31005.0";
					}
					
					deploymentNode.Attributes.Append (doc.CreateAttribute ("RuntimeVersion")).Value = runtimeVersion;
				}

				XmlNamespaceManager mgr = new XmlNamespaceManager (doc.NameTable);
				mgr.AddNamespace ("dep", depNS);
				XmlNode partsNode = deploymentNode.SelectSingleNode ("dep:Deployment.Parts", mgr);
				if (partsNode == null)
					partsNode = deploymentNode.AppendChild (doc.CreateElement ("Deployment.Parts", depNS));

				AddAssemblyPart (doc, partsNode, conf.CompiledOutputName);
				foreach (ProjectReference pr in proj.References) {
					if (pr.LocalCopy) {
						var pk = pr.Package;
						if (pk == null || !pk.IsFrameworkPackage || pk.Name.EndsWith ("-redist")) {
							foreach (string s in pr.GetReferencedFileNames (slnConf))
								AddAssemblyPart (doc, partsNode, s);
						}
					}
				}

			} catch (XmlException ex) {
				monitor.ReportError ("Error processing manifest template.", ex);
				res.AddError (template, ex.LineNumber, ex.LinePosition, null, "Error processing manifest template: '" + ex.Source);
				res.FailedBuildCount++;
				return res;
			}
			
			doc.Save (manifest);

			return res;
		}
Exemplo n.º 3
0
        protected override bool GetNeedsBuilding(SolutionEntityItem item, ConfigurationSelector configuration)
        {
            MoonlightProject           proj = item as MoonlightProject;
            DotNetProjectConfiguration conf = null;

            if (proj != null)
            {
                conf = proj.GetConfiguration(configuration) as DotNetProjectConfiguration;
            }
            if (conf == null)
            {
                return(base.GetNeedsBuilding(item, configuration));
            }

            if (base.GetNeedsBuilding(item, configuration))
            {
                return(true);
            }

            var objDir = GetObjDir(proj, conf);

            DateTime xapLastMod = DateTime.MaxValue;

            if (proj.XapOutputs)
            {
                var xapName = GetXapName(proj, conf);
                if (!File.Exists(xapName))
                {
                    return(true);
                }
                xapLastMod = File.GetLastWriteTime(xapName);
            }

            var manifest = conf.OutputDirectory.Combine("AppManifest.xaml");

            if (proj.GenerateSilverlightManifest)
            {
                if (!File.Exists(manifest))
                {
                    return(true);
                }
                if (!String.IsNullOrEmpty(proj.SilverlightManifestTemplate))
                {
                    string template = proj.GetAbsoluteChildPath(proj.SilverlightManifestTemplate);
                    if (File.Exists(template) && File.GetLastWriteTime(template) > File.GetLastWriteTime(manifest))
                    {
                        return(true);
                    }
                }
            }

            if (proj.CreateTestPage)
            {
                string testPageFile = GetTestPageFileName(proj, conf);
                if (!File.Exists(testPageFile))
                {
                    return(true);
                }
            }

            string   appName    = proj.Name;
            var      resFile    = objDir.Combine(appName + ".g.resources");
            DateTime resLastMod = DateTime.MinValue;

            if (File.Exists(resFile))
            {
                resLastMod = File.GetLastWriteTime(resFile);
            }

            foreach (ProjectFile pf in proj.Files)
            {
                if ((pf.BuildAction == BuildAction.Page || pf.BuildAction == BuildAction.ApplicationDefinition || pf.BuildAction == BuildAction.Resource) &&
                    File.GetLastWriteTime(pf.FilePath) > resLastMod)
                {
                    return(true);
                }
                if (pf.FilePath.Extension == ".xaml" && pf.Generator == "MSBuild:MarkupCompilePass1")
                {
                    var outFile = objDir.Combine(proj.LanguageBinding.GetFileName(pf.FilePath.FileName + ".g"));
                    if (!File.Exists(outFile) || File.GetLastWriteTime(outFile) < File.GetLastWriteTime(pf.FilePath))
                    {
                        return(true);
                    }
                }
                if (pf.BuildAction == BuildAction.Content && File.GetLastWriteTime(pf.FilePath) > xapLastMod)
                {
                    return(true);
                }
            }
            return(false);
        }