2

I am using SharpSVN dll with my Visual Studio 2010 to get the latest revision number so I can version my project using this number. I tried this piece of code below but it gives me error saying:

Can't determine the user's config path

I don't even understand what that means. All I want to do is provide the svn link, my credentials like username and password and get the latest revision number.

Here is the code I tried so far:

using(SvnClient client = new SvnClient())
{
    //client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);
    Collection<SvnLogEventArgs> list;
    client.Authentication.DefaultCredentials = new NetworkCredential("john.locke", "s7y5543a!!");

    SvnLogArgs la = new SvnLogArgs();
    client.GetLog(new Uri("https://100.10.20.12/svn/P2713888/trunk/src/"), la, out list);

    string sRevisionNumber = string.Empty;
    int iRevisionNumber = 0;
    foreach(SvnLogEventArgs a in list)
    {
       if (Convert.ToInt32(a.Revision) > iRevisionNumber)
       {
           iRevisionNumber = Convert.ToInt32(a.Revision);
       }
    }
    RevisionNumber.Text = iRevisionNumber.ToString();
}

other ways to get the revision number may also be selected as answer.

Cute Bear
  • 3,223
  • 13
  • 44
  • 69

1 Answers1

6

I had this problem as well-- needing to find/set properties on the SvnClient before use. Here's what I ended up using. Try using this method instead of just instantiating your client object-- it will auto-create a config folder if it doesn't already exist:

private SvnClient GetClient()
{
    SvnClient client = new SvnClient();

    // Note: Settings creds up here is optional
    // client.Authentication.DefaultCredentials = _creds;

    string configPath = Path.Combine(Path.GetTempPath(), "sharpsvn");
    if (!Directory.Exists(configPath))
    {
        Directory.CreateDirectory(configPath);
    }
    client.LoadConfiguration(configPath, true);

    return client;
}

Alternately, if you want to minimize File IO checking to see if the directory exists, you can try LoadConfiguration, and only create and reassign the directory if that call failed, but just checking each time is simpler.

At any rate, you can then get the latest revision number for a location using the following code:

public long GetLatestRevisionNumber(Uri svnPath)
{
    using (SvnClient client = GetClient())
    {
        SvnInfoEventArgs info;
        client.GetInfo(svnPath, out info);
        return info.LastChangeRevision;
     }
}