AddinData BuildProjectAddin(BuildContext ctx, SourceTagInfo stag, string logFile, string sourcePath, AppReleaseInfo rel, AddinProjectAddin addin) { SetupService ss = new SetupService (); bool generatedXplatPackage = false; HashSet<string> foundPlatforms = new HashSet<string> (); AddinData ainfo = new AddinData (); foreach (AddinProjectSource psource in addin.Sources) { if (string.IsNullOrEmpty (psource.AddinFile)) throw new Exception ("AddinFile element not found in addin-project.xml"); string platforms = psource.Platforms; if (string.IsNullOrEmpty (platforms)) platforms = ctx.Application.Platforms; string[] platformList = platforms.Split (new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); foreach (string plat in platformList) if (!foundPlatforms.Add (plat)) throw new Exception ("Platform " + plat + " specificed in more than open Project element"); string outFile = NormalizePath (psource.AddinFile); if (!string.IsNullOrEmpty (psource.BuildFile)) { // Build the project string solFile = Path.Combine (sourcePath, NormalizePath (psource.BuildFile)); string ops = " \"/p:ReferencePath=" + rel.GetAssembliesPath (ctx) + "\""; if (!string.IsNullOrEmpty (psource.BuildConfiguration)) ops += " \"/property:Configuration=" + psource.BuildConfiguration + "\""; ops = ops + " \"" + solFile + "\""; StringBuilder output = new StringBuilder (); try { // Clean the project RunCommand (ctx.LocalSettings.MSBuildCommand, "/t:Clean " + ops, output, output, Timeout.Infinite); // Build RunCommand (ctx.LocalSettings.MSBuildCommand, ops, output, output, Timeout.Infinite); } finally { File.AppendAllText (logFile, "<pre>" + HttpUtility.HtmlEncode (output.ToString ()) + "</pre>"); } } // Generate the package string tmpPath = Path.Combine (sourcePath, "tmp"); File.AppendAllText (logFile, "<p><b>Building Package</b></p>"); LocalStatusMonitor monitor = new LocalStatusMonitor (); try { if (Directory.Exists (tmpPath)) Directory.Delete (tmpPath, true); Directory.CreateDirectory (tmpPath); ss.BuildPackage (monitor, tmpPath, Path.Combine (sourcePath, outFile)); string file = Directory.GetFiles (tmpPath, "*.mpack").FirstOrDefault (); if (file == null) throw new Exception ("Add-in generation failed"); AddinInfo ai = ReadAddinInfo (file); ainfo.AddinVersion = ai.Version; ainfo.AddinId = Mono.Addins.Addin.GetIdName (ai.Id); if (!generatedXplatPackage && platformList.Length > 0) { File.Copy (file, Path.Combine (stag.GetPackagePath (ctx), "All.mpack"), true); generatedXplatPackage = true; } else { foreach (string plat in platformList) { File.Copy (file, Path.Combine (stag.GetPackagePath (ctx), plat + ".mpack"), true); } } } finally { try { Directory.Delete (tmpPath, true); } catch { } File.AppendAllText (logFile, "<pre>" + HttpUtility.HtmlEncode (monitor.ToString ()) + "</pre>"); } } ainfo.Platforms = string.Join (" ", foundPlatforms.ToArray ()); ainfo.AppVersion = rel.AppVersion; return ainfo; }
AddinData BuildProjectAddin(BuildContext ctx, SourceTagInfo stag, string logFile, string sourcePath, AppReleaseInfo rel, AddinProjectAddin addin) { SetupService ss = new SetupService(); bool generatedXplatPackage = false; HashSet <string> foundPlatforms = new HashSet <string> (); AddinData ainfo = new AddinData(); foreach (AddinProjectSource psource in addin.Sources) { if (string.IsNullOrEmpty(psource.AddinFile)) { throw new Exception("AddinFile element not found in addin-project.xml"); } string platforms = psource.Platforms; if (string.IsNullOrEmpty(platforms)) { platforms = ctx.Application.Platforms; } string[] platformList = platforms.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); foreach (string plat in platformList) { if (!foundPlatforms.Add(plat)) { throw new Exception("Platform " + plat + " specificed in more than open Project element"); } } string outFile = NormalizePath(psource.AddinFile); if (!string.IsNullOrEmpty(psource.BuildFile)) { // Build the project // Move the sources to the work area (which is sandboxed) if (!Directory.Exists(ctx.LocalSettings.WorkAreaPath)) { Directory.CreateDirectory(ctx.LocalSettings.WorkAreaPath); } string workArea = Path.Combine(ctx.LocalSettings.WorkAreaPath, "builder"); if (Directory.Exists(workArea)) { Directory.Delete(workArea, true); } Directory.Move(sourcePath, workArea); StringBuilder output = new StringBuilder(); try { string solFile = Path.Combine(workArea, NormalizePath(psource.BuildFile)); // Restore packages RunCommand(true, "nuget", "restore \"" + solFile + "\"", output, output, Timeout.Infinite); string refPath = rel.GetAssembliesPath(ctx); if (ContaintsMdTargetsFile(workArea) && !string.IsNullOrEmpty(ctx.LocalSettings.LocalAppInstallPath)) { foreach (var p in ctx.LocalSettings.LocalAppInstallPath.Split(new [] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { var ip = Path.Combine(refPath, "__install", p); if (Directory.Exists(ip)) { refPath = ip; break; } } } string ops = " \"/p:ReferencePath=" + refPath + "\""; if (!string.IsNullOrEmpty(psource.BuildConfiguration)) { ops += " \"/property:Configuration=" + psource.BuildConfiguration + "\""; } ops = ops + " \"" + solFile + "\""; // Clean the project RunCommand(true, ctx.LocalSettings.MSBuildCommand, "/t:Clean " + ops, output, output, Timeout.Infinite); // Build RunCommand(true, ctx.LocalSettings.MSBuildCommand, ops, output, output, Timeout.Infinite); } finally { output = output.Replace(workArea, "/build"); File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(output.ToString()) + "</pre>"); Directory.Move(workArea, sourcePath); } } // Generate the package string tmpPath = Path.Combine(sourcePath, "tmp"); File.AppendAllText(logFile, "<p><b>Building Package</b></p>"); LocalStatusMonitor monitor = new LocalStatusMonitor(); try { if (Directory.Exists(tmpPath)) { Directory.Delete(tmpPath, true); } Directory.CreateDirectory(tmpPath); ss.BuildPackage(monitor, tmpPath, Path.Combine(sourcePath, outFile)); string file = Directory.GetFiles(tmpPath, "*.mpack").FirstOrDefault(); if (file == null) { throw new Exception("Add-in generation failed"); } AddinInfo ai = ReadAddinInfo(file); ainfo.AddinVersion = ai.Version; ainfo.AddinId = Mono.Addins.Addin.GetIdName(ai.Id); if (!generatedXplatPackage && platformList.Length > 0) { File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), "All.mpack"), true); generatedXplatPackage = true; } else { foreach (string plat in platformList) { File.Copy(file, Path.Combine(stag.GetPackagePath(ctx), plat + ".mpack"), true); } } } finally { try { Directory.Delete(tmpPath, true); } catch { } File.AppendAllText(logFile, "<pre>" + HttpUtility.HtmlEncode(monitor.ToString()) + "</pre>"); } } ainfo.Platforms = string.Join(" ", foundPlatforms.ToArray()); ainfo.AppVersion = rel.AppVersion; return(ainfo); }