Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(241)

Side by Side Diff: Tools/Google.Apis.Release/ProjectExtenstions.cs

Issue 12767046: Issue 377: New build for releasing a new version (Closed) Base URL: https://google-api-dotnet-client.googlecode.com/hg/
Patch Set: minor Created 10 years, 6 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 using System;
peleyal 2013/09/14 21:15:14 Google header
peleyal 2013/09/16 12:33:54 Done.
2 using System.Collections.Generic;
3 using System.Diagnostics;
4 using System.IO;
5 using System.Linq;
6 using System.Text;
7 using System.Threading.Tasks;
8
9 using Microsoft.Build.Evaluation;
10
11 using Google.Apis.Utils;
12
13 namespace Google.Apis.Release
14 {
15 /// <summary>Project extensions.</summary>
16 static class ProjectExtenstions
17 {
18 static readonly TraceSource TraceSource = new TraceSource("Google.Apis") ;
19
20 /// <summary>Gets the name of the project.</summary>
21 public static string GetName(this Project project)
22 {
23 return project.DirectoryPath.Substring(project.DirectoryPath.LastInd exOf(Path.DirectorySeparatorChar) + 1);
24 }
25
26 /// <summary>Replaces Assembly version number with the given one.</summa ry>
27 public static void ReplaceVersion(this Project project, string newVersio n)
28 {
29 const string ASSEMBLY_INFO_PREFIX = "[assembly: AssemblyVersion(\"";
30
31 // no need to increase version
32 if (newVersion == null)
33 return;
34
35 var assemblyInfoFile = System.IO.Path.Combine(project.DirectoryPath, "Properties", "AssemblyInfo.cs");
36
37 try
38 {
39 // read all lines and replace the current version with the given newVersion
40 var allLines = File.ReadAllLines(assemblyInfoFile).Select(
41 l =>
42 {
43 // if the line contains assembly information, replace ol d version with new version
44 if (l.StartsWith(ASSEMBLY_INFO_PREFIX))
45 return ReplaceVersionInLine(l, ASSEMBLY_INFO_PREFIX, newVersion);
46 else
47 return l;
48 });
49 File.WriteAllLines(assemblyInfoFile, allLines);
50 }
51 catch (Exception ex)
52 {
53 TraceSource.TraceEvent(TraceEventType.Error, "Exception occurred while replacing version", ex.Message);
54 }
55 }
56
57 /// <summary>Returns the assembly information line with the new version. </summary>
58 private static string ReplaceVersionInLine(string line, string assemblyV ersionPrefix, string newVersion)
59 {
60 var startVersion = assemblyVersionPrefix.Length;
61 // '.*' ends the old version number (e.g 1.2.* or 1.2.0.*)
62 var endVersion = line.IndexOf(".*", startVersion);
63 var oldVersion = line.Substring(startVersion, endVersion - startVers ion);
64 return line.Replace(assemblyVersionPrefix + oldVersion, assemblyVers ionPrefix + newVersion);
65 }
66 }
67 }
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b