Browse Source

Made UpdateAssemblyInfo use NSvn instead of svn.exe.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@320 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
9df71b7ffe
  1. 46
      src/Tools/UpdateAssemblyInfo/Main.cs
  2. 2
      src/Tools/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj

46
src/Tools/UpdateAssemblyInfo/Main.cs

@ -7,6 +7,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Reflection;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Collections.Specialized; using System.Collections.Specialized;
@ -185,7 +186,6 @@ namespace UpdateAssemblyInfo
Console.WriteLine(e.Message); Console.WriteLine(e.Message);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("The revision number of the SharpDevelop version being compiled could not be retrieved."); Console.WriteLine("The revision number of the SharpDevelop version being compiled could not be retrieved.");
Console.WriteLine("Add svn.exe to your path to fix the problem.");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Build continues with revision number '9999'..."); Console.WriteLine("Build continues with revision number '9999'...");
try { try {
@ -199,26 +199,36 @@ namespace UpdateAssemblyInfo
} }
static void RetrieveRevisionNumber() static void RetrieveRevisionNumber()
{ {
ProcessStartInfo psi = new ProcessStartInfo("svn", "info"); // we use NSvn to be independent from the installed subversion client
psi.UseShellExecute = false; // NSvn is a quite big library (>1 MB).
psi.RedirectStandardOutput = true; // We don't want to have it twice in the repository, so we must use the version in the
// subversion addin directory without copying it to the UpdateAssemblyInfo directory.
// That means we have to use reflection on the library.
string oldWorkingDir = Environment.CurrentDirectory;
try { try {
Process process = Process.Start(psi); // Set working directory so msvcp70.dll and msvcr70.dll can be found
process.WaitForExit(); Environment.CurrentDirectory = Path.Combine(oldWorkingDir, "AddIns\\Misc\\SubversionAddIn\\RequiredLibraries");
string output = process.StandardOutput.ReadToEnd(); Assembly asm = Assembly.LoadFrom(Path.Combine(Environment.CurrentDirectory, "NSvn.Core.dll"));
Type clientType = asm.GetType("NSvn.Core.Client");
Regex r = new Regex(@"Revision:\s+(\d+)"); object clientInstance = Activator.CreateInstance(clientType);
Match m = r.Match(output); object statusInstance = clientType.InvokeMember("SingleStatus",
if (m != null && m.Success && m.Groups[1] != null) { BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.Public,
revisionNumber = m.Groups[1].Value; null, clientInstance,
} new object[] { oldWorkingDir });
if (revisionNumber == null || revisionNumber.Equals("") || revisionNumber.Equals("0")) { Type statusType = statusInstance.GetType();
throw new Exception("Could not find revision number in svn output"); object entryInstance = statusType.InvokeMember("Entry",
} BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public,
null, statusInstance, new object[0]);
Type entryType = entryInstance.GetType();
int revision = (int)entryType.InvokeMember("Revision",
BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.Public,
null, entryInstance, new object[0]);
revisionNumber = revision.ToString();
} catch (Exception e) { } catch (Exception e) {
Console.WriteLine("Starting svn.exe failed: " + e.Message); Console.WriteLine("Reading revision number with NSvn failed: " + e.Message);
revisionNumber = ReadRevisionFromFile(); revisionNumber = ReadRevisionFromFile();
} finally {
Environment.CurrentDirectory = oldWorkingDir;
} }
if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") { if (revisionNumber == null || revisionNumber.Length == 0 || revisionNumber == "0") {
throw new ApplicationException("Error reading revision number"); throw new ApplicationException("Error reading revision number");

2
src/Tools/UpdateAssemblyInfo/UpdateAssemblyInfo.csproj

@ -24,7 +24,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Main.cs" /> <Compile Include="Main.cs" />
<Compile Include="Readme.txt" /> <None Include="Readme.txt" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSHARP.Targets" />
</Project> </Project>
Loading…
Cancel
Save