Skip to content

Commit 8aadb99

Browse files
committed
Updated release packager.
1 parent bf890f7 commit 8aadb99

8 files changed

+174
-20
lines changed

.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,8 @@ PhpVHReportViewer/Window1.xaml.cs -text
619619
PhpVHReportViewer/app.config -text
620620
ReleasePackager/App.config -text
621621
ReleasePackager/Cleanup.cs -text
622+
ReleasePackager/FileSystemInfoHelper.cs -text
623+
ReleasePackager/MSBuild.cs -text
622624
ReleasePackager/PhpVH.alx -text
623625
ReleasePackager/Program.cs -text
624626
ReleasePackager/Properties/AssemblyInfo.cs -text

ReleasePackager/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33
<startup>
44
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
55
</startup>
6+
<appSettings>
7+
<add key="buildExe" value="%WINDIR%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe"/>
8+
</appSettings>
69
</configuration>
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
using Components;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.IO;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ReleasePackager
10+
{
11+
public static class FileSystemInfoHelper
12+
{
13+
public static bool TryDelete(FileSystemInfo info)
14+
{
15+
if (!info.Exists)
16+
{
17+
return false;
18+
}
19+
20+
var success = true;
21+
var dir = info as DirectoryInfo;
22+
23+
if (dir != null)
24+
{
25+
var children = dir
26+
.GetFiles()
27+
.OfType<FileSystemInfo>()
28+
.Concat(dir.GetDirectories());
29+
30+
foreach (var f in children)
31+
{
32+
if (!TryDelete(f))
33+
{
34+
success = false;
35+
}
36+
}
37+
}
38+
39+
info.Delete();
40+
41+
return success;
42+
}
43+
}
44+
}

ReleasePackager/MSBuild.cs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Diagnostics;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace ReleasePackager
10+
{
11+
public class MSBuild
12+
{
13+
private static string _buildExe = Environment.ExpandEnvironmentVariables(ConfigurationManager.AppSettings["buildExe"]);
14+
15+
public static void Build(string csProj)
16+
{
17+
var argsFormat = "/t:rebuild /p:Configuration=Debug {0}";
18+
var args = string.Format(argsFormat, csProj);
19+
20+
var p = Process.Start(new ProcessStartInfo(_buildExe, args)
21+
{
22+
UseShellExecute = false,
23+
});
24+
25+
p.WaitForExit();
26+
27+
if (p.ExitCode != 0)
28+
{
29+
var msg = string.Format("Process exited with code 0x{0:x8} ({0})", p.ExitCode);
30+
throw new InvalidOperationException(msg);
31+
}
32+
}
33+
}
34+
}

ReleasePackager/PhpVH.alx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#'Std';
2+
23
ret {
34
root: '..\\..\\..\\',
45
output: '..\\..\\..\\release',
56
mainProject: "PhpVH\\PhpVH.csproj",
67
projects: [
7-
"PhpVH.SelfTest\\PhpVH.SelfTest.csproj",
8-
"PhpVH.Tests.Integration\\PhpVH.Tests.Integration.csproj",
98
"PhpVHGui\\PhpVHGui.csproj",
109
"PhpVHReportViewer\\PhpVHReportViewer.csproj",
1110
"PhpVH\\PhpVH.csproj",

ReleasePackager/Program.cs

+68-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.IO;
7+
using System.IO.Compression;
78
using System.Linq;
89
using System.Reflection;
910
using System.Text;
@@ -17,9 +18,11 @@ class Program
1718
{
1819
private static Release _currentRelease;
1920

20-
static Version GetReleaseVersion(ReleaseProject[] projects)
21+
private static DirectoryInfo outputDir;
22+
23+
static ReleaseProject GetMainProject(ReleaseProject[] projects)
2124
{
22-
return projects.Single(x => x.IsMainProject).Version;
25+
return projects.Single(x => x.IsMainProject);
2326
}
2427

2528
private static void WriteHeader(string format, params string[] args)
@@ -37,7 +40,7 @@ private static void WriteProgressHeader(string text)
3740
Cli.WriteLine(" ~Blue~~|White~{0,-" + (Console.BufferWidth - 2) + "}~R~", text);
3841
}
3942

40-
static void Main(string[] args)
43+
private static void LoadSettings()
4144
{
4245
WriteHeader("Loading release settings");
4346
var script = "PhpVH.alx";
@@ -47,11 +50,25 @@ static void Main(string[] args)
4750
_currentRelease = interpreter.GetReturnValue().ConvertTo<Release>();
4851
var projects = _currentRelease.Projects;
4952
Cli.WriteLine();
53+
}
5054

51-
WriteHeader("Copying binaries");
55+
private static void Build()
56+
{
57+
WriteHeader("Building");
5258

53-
var outputDir = new DirectoryInfo(_currentRelease.Output)
54-
.Combine(GetReleaseVersion(projects).ToString());
59+
foreach (var p in _currentRelease.Projects)
60+
{
61+
p.Clean();
62+
p.Build();
63+
}
64+
}
65+
66+
private static void CopyBinaries()
67+
{
68+
WriteHeader("Copying binaries");
69+
var mainProject = GetMainProject(_currentRelease.Projects);
70+
outputDir = new DirectoryInfo(_currentRelease.Output)
71+
.Combine(mainProject.GetVersion().ToString());
5572

5673
if (outputDir.Exists)
5774
{
@@ -62,10 +79,10 @@ static void Main(string[] args)
6279
Cli.WriteLine();
6380
WriteProgressHeader("Copying");
6481

65-
var progress = new CliProgressBar(projects.Length);
82+
var progress = new CliProgressBar(_currentRelease.Projects.Length);
6683
progress.Write();
6784

68-
projects
85+
_currentRelease.Projects
6986
.Iter(x =>
7087
{
7188
new DirectoryInfo(x.OutputPath).CopyTo(outputDir.FullName, true);
@@ -75,6 +92,10 @@ static void Main(string[] args)
7592

7693
Cli.WriteLine();
7794
Cli.WriteLine();
95+
}
96+
97+
private static void Cleanup()
98+
{
7899
WriteHeader("Cleaning up");
79100
Cli.WriteLine("Searching...");
80101
var fsos = new List<FileSystemInfo>();
@@ -101,11 +122,18 @@ static void Main(string[] args)
101122
Cli.WriteLine();
102123
WriteProgressHeader("Deleting");
103124

104-
progress = new CliProgressBar(fsos.Count);
125+
var progress = new CliProgressBar(fsos.Count);
105126
progress.Write();
106127

107128
fsos.Iter(x =>
108129
{
130+
if (!x.Exists)
131+
{
132+
progress.Value++;
133+
progress.Write();
134+
return;
135+
}
136+
109137
var dir = x as DirectoryInfo;
110138

111139
if (dir != null)
@@ -120,6 +148,37 @@ static void Main(string[] args)
120148
progress.Value++;
121149
progress.Write();
122150
});
151+
Cli.WriteLine();
152+
Cli.WriteLine();
153+
}
154+
155+
private static void ZipRelease()
156+
{
157+
WriteHeader("Zipping");
158+
var name = Path.GetFileNameWithoutExtension(_currentRelease.MainProject);
159+
var zipName = name + outputDir.Name + ".zip";
160+
var zipFile = Path.Combine(outputDir.FullName, "..", zipName);
161+
162+
Cli.WriteLine("Creating ~Cyan~{0}~R~", Path.GetFileName(zipFile));
163+
164+
if (File.Exists(zipFile))
165+
{
166+
Cli.WriteLine("~Yellow~Zip with same name already exists, deleting.~R~");
167+
File.Delete(zipFile);
168+
}
169+
170+
ZipFile.CreateFromDirectory(outputDir.FullName, zipFile);
171+
}
172+
173+
static void Main(string[] args)
174+
{
175+
LoadSettings();
176+
Build();
177+
CopyBinaries();
178+
Cleanup();
179+
ZipRelease();
180+
181+
Cli.WriteLine("Done\r\n");
123182
}
124183
}
125184
}

ReleasePackager/ReleasePackager.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
</PropertyGroup>
3838
<ItemGroup>
3939
<Reference Include="System" />
40+
<Reference Include="System.Configuration" />
4041
<Reference Include="System.Core" />
42+
<Reference Include="System.IO.Compression.FileSystem" />
4143
<Reference Include="System.Xml.Linq" />
4244
<Reference Include="System.Data.DataSetExtensions" />
4345
<Reference Include="Microsoft.CSharp" />
@@ -46,6 +48,8 @@
4648
</ItemGroup>
4749
<ItemGroup>
4850
<Compile Include="Cleanup.cs" />
51+
<Compile Include="FileSystemInfoHelper.cs" />
52+
<Compile Include="MSBuild.cs" />
4953
<Compile Include="Program.cs" />
5054
<Compile Include="Properties\AssemblyInfo.cs" />
5155
<Compile Include="Release.cs" />

ReleasePackager/ReleaseProject.cs

+18-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.IO;
45
using System.Linq;
56
using System.Reflection;
@@ -23,37 +24,45 @@ public class ReleaseProject
2324

2425
public string OutputPath { get; private set; }
2526

26-
public Version Version { get; private set; }
27-
2827
private ReleaseProject() { }
2928

29+
public Version GetVersion()
30+
{
31+
return Assembly.LoadFile(AssemblyName).GetName().Version;
32+
}
33+
34+
public void Clean()
35+
{
36+
FileSystemInfoHelper.TryDelete(new DirectoryInfo(OutputPath));
37+
}
38+
39+
public void Build()
40+
{
41+
MSBuild.Build(CsprojFilename);
42+
}
43+
3044
public static ReleaseProject Load(string projectFilename, string mode)
3145
{
3246
var projectDir = Path.GetDirectoryName(projectFilename);
3347
var document = XDocument.Load(projectFilename);
3448
XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
3549

36-
var outputType = document.Descendants(ns + "OutputType").SingleOrDefault().Value;
37-
3850
var relativeOutputPath = document
3951
.Descendants(ns + "OutputPath")
4052
.SingleOrDefault(x => x.Value.ToLower().Contains(mode.ToLower())).Value;
4153

54+
var outputType = document.Descendants(ns + "OutputType").SingleOrDefault().Value;
4255
var outputPath = Path.Combine(projectDir, relativeOutputPath);
43-
4456
var name = document.Descendants(ns + "AssemblyName").SingleOrDefault().Value;
4557
var fullName = Path.Combine(outputPath, name) + "." + (outputType.ToLower().Contains("exe") ? "exe" : "dll");
46-
47-
var version = Assembly.LoadFile(fullName).GetName().Version;
48-
58+
4959
return new ReleaseProject()
5060
{
5161
Name = name,
5262
AssemblyName = fullName,
5363
CsprojFilename = projectFilename,
5464
ProjectDirectory = projectDir,
5565
OutputPath = outputPath,
56-
Version = version,
5766
};
5867
}
5968
}

0 commit comments

Comments
 (0)