2 // GenerateMoonlightManifest.cs
5 // Michael Hutchinson <mhutchinson@novell.com>
6 // Ankit Jain <jankit@novell.com>
8 // Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
9 // Copyright (c) 2010 Novell, Inc. (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.Collections.Generic;
35 using System.CodeDom.Compiler;
38 using Microsoft.CSharp;
40 using Microsoft.Build.Framework;
41 using Microsoft.Build.Utilities;
43 namespace Moonlight.Build.Tasks {
44 public class GenerateMoonlightManifest : Task {
46 public override bool Execute ()
48 return GenerateManifest ();
51 bool GenerateManifest ()
53 const string depNS = "http://schemas.microsoft.com/client/2007/deployment";
55 string template = null;
56 var manifest = ManifestFile.ItemSpec;
57 Log.LogMessage (MessageImportance.Normal, "Generating manifest file {0}", manifest);
59 if (SilverlightManifestTemplate != null)
60 template = String.IsNullOrEmpty (SilverlightManifestTemplate.ItemSpec) ?
62 SilverlightManifestTemplate.GetMetadata ("FullPath");
64 XmlDocument doc = new XmlDocument ();
65 if (template != null) {
66 if (!File.Exists (template)) {
67 Log.LogError ("Could not find manifest template '" + template + "'.");
73 } catch (XmlException ex) {
74 Log.LogError (null, null, null, template, ex.LineNumber, ex.LinePosition, 0, 0,
75 "Error loading manifest template '" + ex.Source);
77 } catch (Exception ex) {
78 Log.LogError ("Could not load manifest template '" + template + "'.");
79 Log.LogMessage (MessageImportance.Low, "Could not load manifest template '" + template + "': " + ex.ToString ());
84 doc.LoadXml (@"<Deployment xmlns=""http://schemas.microsoft.com/client/2007/deployment"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""></Deployment>");
88 XmlNode deploymentNode = doc.DocumentElement;
89 if (deploymentNode == null || deploymentNode.Name != "Deployment" || deploymentNode.NamespaceURI != depNS) {
90 Log.LogError ("Missing or invalid root <Deployment> element in manifest template '" + template + "'.");
93 if (deploymentNode.Attributes["EntryPointAssembly"] == null)
94 deploymentNode.Attributes.Append (doc.CreateAttribute ("EntryPointAssembly")).Value =
95 EntryPointAssembly.GetMetadata ("Filename");
97 if (!String.IsNullOrEmpty (SilverlightAppEntry) && deploymentNode.Attributes["EntryPointType"] == null)
98 deploymentNode.Attributes.Append (doc.CreateAttribute ("EntryPointType")).Value = SilverlightAppEntry;
100 if (deploymentNode.Attributes["RuntimeVersion"] == null) {
102 /*string fxVersion = MoonlightFrameworkBackend.GetFxVersion (proj.TargetFramework);
104 if (proj.TargetRuntime is MonoDevelop.Core.Assemblies.MonoTargetRuntime) {
105 var package = proj.TargetRuntime.RuntimeAssemblyContext.GetPackage ("moonlight-web-" + fxVersion);
106 if (package != null && package.IsFrameworkPackage) {
107 runtimeVersion = package.Version;
109 LoggingService.LogWarning ("Moonlight core framework package not found, cannot determine " +
110 "runtime version string. Falling back to default value.");
114 deploymentNode.Attributes.Append (doc.CreateAttribute ("RuntimeVersion")).Value =
115 String.IsNullOrEmpty (RuntimeVersion) ? "2.0.31005.0" : RuntimeVersion;
118 XmlNamespaceManager mgr = new XmlNamespaceManager (doc.NameTable);
119 mgr.AddNamespace ("dep", depNS);
120 XmlNode partsNode = deploymentNode.SelectSingleNode ("dep:Deployment.Parts", mgr);
121 if (partsNode == null)
122 partsNode = deploymentNode.AppendChild (doc.CreateElement ("Deployment.Parts", depNS));
124 AddAssemblyPart (doc, partsNode, EntryPointAssembly);
126 foreach (ITaskItem ref_item in References)
127 AddAssemblyPart (doc, partsNode, ref_item);
128 } catch (XmlException ex) {
129 Log.LogError (null, null, null, template, ex.LineNumber, ex.LinePosition, 0, 0,
130 "Error processing manifest template: '" + ex.Source);
139 static void AddAssemblyPart (XmlDocument doc, XmlNode partsNode, ITaskItem filename)
141 XmlNode child = doc.CreateElement ("AssemblyPart", "http://schemas.microsoft.com/client/2007/deployment");
142 child.Attributes.Append (doc.CreateAttribute (
143 "Name", "http://schemas.microsoft.com/winfx/2006/xaml")).Value = filename.GetMetadata ("Filename");
144 string subdir = filename.GetMetadata ("DestinationSubdirectory");
145 child.Attributes.Append (doc.CreateAttribute ("Source")).Value = Path.Combine (subdir ?? String.Empty, Path.GetFileName (filename.ItemSpec));
146 partsNode.AppendChild (child);
151 public ITaskItem ManifestFile {
157 public ITaskItem EntryPointAssembly {
162 public ITaskItem[] References {
166 public ITaskItem SilverlightManifestTemplate {
170 public string SilverlightAppEntry {
174 public string RuntimeVersion {