所以我创建了这个 Web 应用程序,它将调用服务器以获取有关分支、流、变更集信息等的信息。我正在使用 p4api.net.dll 创建 api。我已经下载并提取了它,并按照 perforce 页面上的说明将事物连接到服务器。
**Problem**
Using C# and P4API.NET, how to I create a basic program to connect and disconnect from the server?
**Solution**
The following code can be used as the foundation of a new P4API.NET program. To use and compile this code, follow these steps:
1. Download the zipped P4API.NET from the website(www.perforce.com) or the FTP site(ftp://ftp.perforce.com/perforce). Extract it into a local directory.
2. Open Visual Studio.
3. From the menu, select New->Project...
4. From the Visual C# section, select Console Application
5. Fill in the Name and Location as appropriate.
6. Click the OK Button.
7. Once the new project loads, right-click on the References in the Solution Explorer and select the option Add Reference... from the context menu.
8. Click on the Browse tab. Navigate to the folder where you extracted the P4API.NET zipfile, and go into the lib folder. Select p4api.net.dll (not p4bridge.dll) and click OK.
9. Cut and paste the code from below into the Program.cs file that was automatically created when you created the project, overwriting the default code.
10.Build the code by selecting Build -> Build Solution from the menu.
11.Open Windows Explorer. Navigate to the folder where you extracted the P4API.NET zipfile, and copy the p4bridge.dll file to the bin/Debug directory of your solution. You can set up the solution to copy it automatically, but it only needs to be done once.
12.Run the program with Debug -> Start Debugging
If you want to run the program outside Visual Studio, always make sure that the p4api.net.dll and p4bridge.dll files are included with the binary. The p4api.net.dll file contains the .NET assembly, while the p4bridge.dll contains the Perforce library.
现在,我跳过了第 3-6 步,其余的一直到第 11 步。在我的 webapi 项目中,我没有 bin/Debug 文件夹。我唯一拥有的 Debug 文件夹位于 obj 文件夹中,因此我将其添加到那里。当我运行我的 api 时,我得到以下图像:
到目前为止,我所做的只是使用以下代码建立连接:
string uri = "server:port";
string user = "username";
string ws_client = "ws_name";
Perforce.P4.Server server = new Perforce.P4.Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;
con.UserName = user;
con.Client = new Client();
con.Client.Name = ws_client;
con.Connect(null);
谁能帮我解决这个问题,以便我至少可以开始连接?