我正在尝试使用p4api.net apis开发一个基于C#的构建工具。我是perforce p4api.net的新手。我遵循了从他们的网站下载的p4api.net库中的说明,但在perforce上运行基本命令从未成功过。我附上了一段代码,这是为了从Perforce中获取客户端。如果我错了,请改正。代码在执行GetClients()时抛出运行时错误(未处理的预期)。
static void Main(string[] args)
{
string uri = "perforce:1666";
string user = "User1";
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;
con.UserName = user;
con.Client = new Client();
// connect to the server
con.Connect(null);
// run the command against the current repository
IList<Client> changes = rep.GetClients(null);
}任何有关执行C#文档/示例的有用指南都将不胜感激。
谢谢,马德胡
发布于 2012-07-27 20:40:17
您确定异常来自GetClients吗?我成功地运行了您的代码,但是当我将uri更改为不存在的服务器:端口时,我在con.Connect处得到了未处理的异常(Null)。
确认您确实有权访问安装了User1的perforce:1666服务器,并且User1不需要该服务器上的密码。
发布于 2012-07-27 22:17:22
票证通过p4登录授予用户。如果您使用P4V或其他客户端登录,则票证在过期之前仍然有效,除非您显式地p4注销。您可以在连接之后、运行命令之前在P4API.NET中创建此凭据:
// connect to the server
con.Connect(null);
string password = "pw";
Credential cred = con.Login(password, null, null);
con.Credential = cred;https://stackoverflow.com/questions/11684307
复制相似问题