diff --git a/Builder/Builder.csproj b/Builder/Builder.csproj index 2f2b2c5..9e4f00d 100644 --- a/Builder/Builder.csproj +++ b/Builder/Builder.csproj @@ -12,6 +12,7 @@ Builder v3.5 512 + false publish\ true Disk @@ -24,7 +25,6 @@ true 0 1.0.0.%2a - false false true @@ -63,6 +63,7 @@ + diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt new file mode 100644 index 0000000..b2412e3 --- /dev/null +++ b/Builder/IISMainHandler/build.txt @@ -0,0 +1 @@ +62 \ No newline at end of file diff --git a/Builder/IISMainHandler/postbuild.bat b/Builder/IISMainHandler/postbuild.bat new file mode 100644 index 0000000..1d93fdd --- /dev/null +++ b/Builder/IISMainHandler/postbuild.bat @@ -0,0 +1,5 @@ +@echo off +del Templates.7z +del Templates.bat +ping localhost -n 2 >nul +del 7z.exe \ No newline at end of file diff --git a/Builder/IISMainHandler/prebuild.bat b/Builder/IISMainHandler/prebuild.bat new file mode 100644 index 0000000..e502560 --- /dev/null +++ b/Builder/IISMainHandler/prebuild.bat @@ -0,0 +1,3 @@ +@echo off +"C:\Program Files\7-Zip\7z.exe" a Templates.7z ..\..\templates\* -xr!.svn +copy "C:\Program Files\7-Zip\7z.exe" 7z.exe \ No newline at end of file diff --git a/Builder/IISMainHandler/product.wxs b/Builder/IISMainHandler/product.wxs new file mode 100644 index 0000000..79a5b3d --- /dev/null +++ b/Builder/IISMainHandler/product.wxs @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Builder/Program.cs b/Builder/Program.cs index 795056d..f6c2d55 100644 --- a/Builder/Program.cs +++ b/Builder/Program.cs @@ -4,12 +4,24 @@ using System.Linq; using System.Text; using System.IO; //using Microsoft.Tools.WindowsInstallerXml; -//using System.Xml; +using System.Xml; using System.Diagnostics; using System.Configuration; namespace Builder { class Program { + + private static string runBatFile(string filename) { + ProcessStartInfo info = new ProcessStartInfo(filename); + info.WorkingDirectory = (new FileInfo(filename)).Directory.FullName; + info.UseShellExecute = false; + info.RedirectStandardOutput = true; + using(Process process = Process.Start(info)) { + process.WaitForExit(); + return process.StandardOutput.ReadToEnd(); + } + } + static void Main(string[] args) { try { @@ -27,23 +39,77 @@ namespace Builder { string sourceFile = fullPath + "product.wxs"; if(!File.Exists(sourceFile)) throw new ApplicationException("No wxs file could be found"); string targetFile = fullPath + "product.wixobj"; + string wixPdbFile = fullPath + "product.wixpdb"; string outputFile = fullPath + "product.msi"; + string prebuildCommands = fullPath + "prebuild.bat"; + string postbuildCommands = fullPath + "postbuild.bat"; + string buildNumberFile = fullPath + "build.txt"; + + if(File.Exists(prebuildCommands)) Console.WriteLine(runBatFile(prebuildCommands)); + + if(!File.Exists(buildNumberFile)) { + using(FileStream stream = File.Create(buildNumberFile)) { + using(StreamWriter writer = new StreamWriter(stream)) { + writer.Write("0"); + } + } + } + int buildNumber; + using(StreamReader reader = new StreamReader(buildNumberFile)) { + buildNumber = int.Parse(reader.ReadToEnd()); + } + buildNumber++; //NO CONCURRENCY HERE + using(StreamWriter writer = new StreamWriter(buildNumberFile)) { + writer.Write(buildNumber); + } - ProcessStartInfo candleInfo = new ProcessStartInfo(WIXPATH + "candle.exe", "-nologo -out \"" + targetFile + "\" \"" + sourceFile + "\""); - candleInfo.UseShellExecute = false; - candleInfo.RedirectStandardOutput = true; - Process candle = Process.Start(candleInfo); - //candle.Start(); - candle.WaitForExit(); - Console.Write(candle.StandardOutput.ReadToEnd()); + int revNumber; + ProcessStartInfo svnInfo = new ProcessStartInfo(SVNPATH + "svn", "info --xml"); + svnInfo.WorkingDirectory = (new DirectoryInfo(".")).Parent.FullName; + svnInfo.UseShellExecute = false; + svnInfo.RedirectStandardOutput = true; + using(Process svn = Process.Start(svnInfo)) { + svn.WaitForExit(); + XmlDocument document = new XmlDocument(); + document.Load(svn.StandardOutput); + revNumber = int.Parse(document.GetElementsByTagName("entry")[0].Attributes["revision"].Value); + } + + using(TempFile tempFile = new TempFile()) { + + string wxsData; + using(StreamReader sourceReader = new StreamReader(sourceFile)) { + wxsData = sourceReader.ReadToEnd(); + } + wxsData = wxsData.Replace("{rev}", revNumber.ToString()).Replace("{build}", buildNumber.ToString()); + + using(StreamWriter tempWriter = tempFile.getWriter()) { + tempWriter.Write(wxsData); + } + + ProcessStartInfo candleInfo = new ProcessStartInfo(WIXPATH + "candle.exe", "-nologo -arch x64 -out \"" + targetFile + "\" \"" + tempFile.fileName + "\""); + candleInfo.UseShellExecute = false; + candleInfo.RedirectStandardOutput = true; + using(Process candle = Process.Start(candleInfo)) { + //candle.Start(); + candle.WaitForExit(); + Console.Write(candle.StandardOutput.ReadToEnd()); + } + } ProcessStartInfo lightInfo = new ProcessStartInfo(WIXPATH + "light.exe", "-nologo -out \"" + outputFile + "\" \"" + targetFile + "\""); lightInfo.UseShellExecute = false; lightInfo.RedirectStandardOutput = true; - Process light = Process.Start(lightInfo); - //light.Start(); - light.WaitForExit(); - Console.Write(light.StandardOutput.ReadToEnd()); + using(Process light = Process.Start(lightInfo)) { + //light.Start(); + light.WaitForExit(); + Console.Write(light.StandardOutput.ReadToEnd()); + } + + File.Delete(targetFile); + if(File.Exists(wixPdbFile)) File.Delete(wixPdbFile); + + if(File.Exists(postbuildCommands)) Console.WriteLine(runBatFile(postbuildCommands)); /* Preprocessor preprocessor = new Preprocessor(); preprocessor.CurrentPlatform = Platform.X86; diff --git a/Builder/TempFile.cs b/Builder/TempFile.cs new file mode 100644 index 0000000..b02f205 --- /dev/null +++ b/Builder/TempFile.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; + +namespace Builder { + class TempFile : IDisposable { + + public readonly string fileName; + + public TempFile() { + this.fileName = Path.GetTempFileName(); + } + + public StreamReader getReader() { + return new StreamReader(this.fileName); + } + + public StreamWriter getWriter() { + return new StreamWriter(this.fileName); + } + + public void Dispose() { + File.Delete(this.fileName); + } + + } +}