Hello,
how can I automatically query the current revision from Tortoise Subversion and
log it in my C# app?
Revision, date and comment is best
Do you have any tips?
HTML / XML
if exist "C:\Program Files\TortoiseSVN\bin\SubWCRev.exe"
"C:\Program Files\TortoiseSVN\bin\SubWCRev.exe"
"$(ProjectDir)."
"$(ProjectDir)Properties\AssemblyInfo.Base.cs"
"$(ProjectDir)Properties\AssemblyInfo.cs"

Jignesh KumarRank #91 · 22.9K reputationPosted Aug 14, 2024, 7:55 AM EDT
Hello Thomas,
You can create class to read svn revision info step by step, Create below class and call method in program file to get latest change done in SVN,
Note : Here I have created console application but you
public class SvnInfoFetcher { public static void GetSvnInfo(string workingDirectory) { // Create a new process to run the svn info command Process svnProcess = new Process { StartInfo = new ProcessStartInfo { FileName = "svn", Arguments = "info", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true, WorkingDirectory = workingDirectory // Set the working directory to your SVN directory } }; // Start the process and read the output svnProcess.Start(); string output = svnProcess.StandardOutput.ReadToEnd(); svnProcess.WaitForExit(); // Parse the output for the required information ParseSvnInfo(output); } private static void ParseSvnInfo(string svnInfoOutput) { string revision = ""; string date = ""; string lastChangedAuthor = ""; string lastChangedRev = ""; string lastChangedDate = ""; // Split the output by line string[] lines = svnInfoOutput.Split(new[] { Environment.NewLine }, StringSplitOptions.None); foreach (string line in lines) { if (line.StartsWith("Revision:")) { revision = line.Substring("Revision:".Length).Trim(); } else if (line.StartsWith("Last Changed Author:")) { lastChangedAuthor = line.Substring("Last Changed Author:".Length).Trim(); } else if (line.StartsWith("Last Changed Rev:")) { lastChangedRev = line.Substring("Last Changed Rev:".Length).Trim(); } else if (line.StartsWith("Last Changed Date:")) { lastChangedDate = line.Substring("Last Changed Date:".Length).Trim(); } } // Log or display the information Console.WriteLine($"Revision: {revision}"); Console.WriteLine($"Last Changed Author: {lastChangedAuthor}"); Console.WriteLine($"Last Changed Rev: {lastChangedRev}"); Console.WriteLine($"Last Changed Date: {lastChangedDate}"); } } class Program { static void Main() { string workingDirectory = @"C:\Path\To\Your\SVN\Working\Copy"; SvnInfoFetcher.GetSvnInfo(workingDirectory); } }jammy anderson15 reputationPosted Aug 17, 2024, 2:40 AM EDT
To automatically query the current revision from TortoiseSVN and log it in your C# app, you can use the following approach:
Use
svnCommand Line:svn infocommand to get revision information:svn info --xmlParse XML Output in C#:
Here's a sample code snippet for executing the command and parsing the XML:
using System; using System.Diagnostics; using System.Xml; class Program { static void Main() { // Execute svn info command var process = new Process { StartInfo = new ProcessStartInfo { FileName = "svn", Arguments = "info --xml", RedirectStandardOutput = true, UseShellExecute = false, CreateNoWindow = true } }; process.Start(); // Read the output var output = process.StandardOutput.ReadToEnd(); process.WaitForExit(); // Parse XML var xmlDoc = new XmlDocument(); xmlDoc.LoadXml(output); var revision = xmlDoc.SelectSingleNode("//entry/@revision")?.Value; var date =xmlDoc.SelectSingleNode("//commit/date")?.InnerText; var comment = xmlDoc.SelectSingleNode("//commit/msg")?.InnerText; // Log the information Console.WriteLine($"Revision: {revision}"); Console.WriteLine($"Date: {date}"); Console.WriteLine($"Comment: {comment}"); } }Make sure the
svncommand-line tool is installed and accessible from your application. Adjust the XML parsing as needed based on your actual output.Thomas Adler60 reputationPosted Aug 17, 2024, 2:43 PM EDT
Hello,
my goal is to see the revision number at the customer, with which revision created.
If I have to call a process, this is not possible.
I have a project with n files.
How can I create and query a branch so that I get all the files to compile?
Thanks for tips.
Regards
Thomas Adler60 reputationPosted Aug 25, 2024, 1:11 PM EDT
Yes.
Is it possible for my application to write the revision to the log file without it being installed at the customer?
I only want to know the current revision that is installed at the customer.
Can you please give me an answer, then we can close the thread. Thanks to all.