问题
I'm currently developing an application in .NET 4 which has to interact with a Perforce server.
My team previously developed some sort of wrapper using the Perforce API, but its missing quite a few use-cases and doesn't properly handle exceptions. In short, it's not something that I can really use as-is, as it would require considerable effort to make it as "bullet-proof" as possible.
I was wondering if there's a Perforce API wrapper that exists for .NET which properly handles exceptions ?
As I was evaluating the usability of our in-house wrapper, I came up with a list of exceptions and use-cases our application would need to handle (and the wrapper would need to throw).
The list was quite exhaustive, which prompted me to wonder if some sort of wrapper already existed.
回答1:
You might want to check out the P4API.NET library, which is provided by Perforce. Or you could use the P4.NET library, which isn't an official release from Perforce, but has been around for a while.
I've used P4.NET several times, and been pretty happy with it. You can get the .NET 4 libraries here, as I believe the original library only had support for .NET 2.
回答2:
There is also my (not that well tested) c# wrapper around the p4 exe. The main (only?) advantage of this over the others is that it builds and works under mono too. It does not depend on COM or the perforce C++ libraries.
https://github.com/inorton/p4-sharp
P4Shell p = new P4Shell();
if ( p.Login("inb","password") )
Console.WriteLine("logged in");
Console.WriteLine( p.WorkspaceName );
Console.WriteLine( p.WorkspaceRoot );
var dirs = p.Dirs("//nCipher/dev/home/inb/*");
foreach ( var d in dirs )
Console.WriteLine(" + {0}", d);
P.S. I wasn't trying to be funny by storing it in github :)
来源:https://stackoverflow.com/questions/9146677/net-wrapper-for-perforce-api