我使用CollabNET的SharpSvn库.我想在提交时设置修订版作者,但我总是以我的 Windows用户名提交. 这对我不起作用: System.Net.NetworkCredential oCred = new System.Net.NetworkCredential("user", "pass");client.
这对我不起作用:
System.Net.NetworkCredential oCred = new System.Net.NetworkCredential("user", "pass"); client.Authentication.DefaultCredentials = oCred;
我也试过了:
client.SetProperty("", "svn:author", "user");
但我得到一个错误,目标(第一个参数)是坏的.
那么请你告诉我如何在c#中设置提交到subversion存储库的用户(作者)?
这完全取决于您如何连接到您的存储库,因为存储库负责为修订添加用户名. (它通常会复制连接的凭据,但不必这样做).当您使用file:/// repository(通常不建议使用 – 请参阅The Subversion Book)时,您可以直接在提交时解决此问题.
using (SvnClient client = new SvnClient()) { client.Authentication.Clear(); // Clear predefined handlers // Install a custom username handler client.Authentication.UserNameHandlers += delegate(object sender, SvnUserNameEventArgs e) { e.UserName = "MyName"; }; SvnCommitArgs ca = new SvnCommitArgs { LogMessage = "Hello" } client.Commit(dir, ca); }
如果连接到远程存储库,则可以在存储库中安装pre-revprop-change挂钩时更改修订的作者(请参阅The Subversion Book)
using (SvnClient client = new SvnClient()) { client.SetRevisionProperty(new Uri("http://my/repository"), 12345, SvnPropertyNames.SvnAuthor, "MyName"); // Older SharpSvn releases allowed only the now obsolete syntax client.SetRevisionProperty( new SvnUriTarget(new Uri("http://my/repository"), 12345), SvnPropertyNames.SvnAuthor, "MyName"); }
[2009-08-14]
更新的SharpSvn版本也允许这样:
using (SvnRepositoryClient rc = new SvnRepositoryClient()) { SvnSetRevisionPropertyRepositoryArgs ra; ra.CallPreRevPropChangeHook = false; ra.CallPostRevPropChangeHook = false; rc.SetRevisionProperty(@"C:\Path\To\Repository", 12345, SvnPropertyNames.SvnAuthor, "MyName", ra); }
最后一个示例假定直接访问存储库,但它会绕过存储库挂钩以获得最佳性能.