|
| 1 | +# Build instructions for P4API.NET |
| 2 | + |
| 3 | +These are Build instructions for P4API.net and its required DLL and various test utilities |
| 4 | + |
| 5 | +## The .NET Core (6.0) cross-platform port |
| 6 | + |
| 7 | +With the 2021.2 release, `P4API.NET` has been extended to support .NET CORE and to be cross-platform on three Target OS's (Windows, Linux, OSX) |
| 8 | + |
| 9 | +P4API.NET consists of a DLL written in C++ which contains the Perforce C++ API, which is wrapped by a layer of C# code which exports the .NET interface. |
| 10 | + |
| 11 | +The bridge code is dependent on P4API release 21.2 or above. |
| 12 | + |
| 13 | +Within this directory are several subprojects. p4bridge, p4bridge-unit-test, p4bridgeStressTest, p4api.net and p4api.net-unit-test |
| 14 | + |
| 15 | +## Getting to know your solutions |
| 16 | + |
| 17 | +### p4apicore.net.sln |
| 18 | + |
| 19 | +[p4apicore.net.sln](p4apicore.net.sln) - This solution includes projects [p4api.net.csproj](./p4api.net/p4api.net.csproj) and [p4api.net-unit-test.csproj](./p4api.net-unit-test/p4api.net-unit-test.csproj). |
| 20 | +Both of the projects target frameworks .NET Framework 4.6.2, .Net Core 6.0 and .NET Standard 2.0. |
| 21 | +> It only includes the C# portions of the project. |
| 22 | +> It can be built using the `dotnet build p4apicore.net.sln` command. |
| 23 | +This solution can be opened by the "dotnet" executable on any supported platform, or by VS2019+ on windows only. |
| 24 | +This is the primary solution to be used for building and/or debugging P4API.NET and its unit tests. |
| 25 | + |
| 26 | +### Sample Applications |
| 27 | + |
| 28 | +Sample Console Applications for .NET 6.0 are provided here: |
| 29 | +[consoleApps/ControlCTest.sln](consoleApps/ControlCTest.sln) and [consoleApps/P4DotNetConsole.sln](consoleApps/P4DotNetConsole.sln) |
| 30 | + |
| 31 | +Sample Applications for .NET framework are provided here: |
| 32 | +[examples/examples.sln](examples/examples.sln) |
| 33 | + |
| 34 | +### What about VS Code? |
| 35 | + |
| 36 | +The workspace file [p4apinet.code-workspace](./p4apinet.code-workspace) opens the P4API.NET C# source tree for the assembly and its Unit Tests. |
| 37 | +This workspace has not been customized for C# and cannot be used to build the distribution on any platform. |
| 38 | + |
| 39 | +The workspace file [p4bridge.code-workspace](./p4bridge.code-workspace) shows the P4BRIDGE C++ source tree and the source for the p4bridge-unit-test. |
| 40 | +This workspace has not been customized for C++ and CMake and cannot be used to build the distribution on any platform. |
| 41 | + |
| 42 | +Enhancing these workspaces to actually do builds is an exercise for the reader ;) |
| 43 | + |
| 44 | +## Setting up the C++ build environment |
| 45 | + |
| 46 | +C++ is used for the *p4bridge*, *p4bridge-unit-test* and *p4bridgeStressTest* projects, which are all in subdirectories of the p4api.net top-level directory. All C++ builds use Cmake. |
| 47 | + |
| 48 | +### Updating cmake |
| 49 | + |
| 50 | +The *p4bridge*, *p4bridge-unit-test* and *p4bridgeStressTest* projects require cmake 3.20 or better, (for CMake Profile support). |
| 51 | + |
| 52 | +The default installation of cmake on ubuntu will require updating. |
| 53 | +to update to the latest version on ubuntu, follow package updating instructions here: [CMake APT repository](https://apt.kitware.com) |
| 54 | + |
| 55 | +### Getting the P4API and openssl 1.1.1 libraries |
| 56 | + |
| 57 | +We've included some sample setup scripts for copying the P4API and openssl libraries into their expected source subdirectories. They are found in the root p4api.net directory. |
| 58 | +look for *setuplibrary.bat*, *setuplibrary_linux.sh* and *setuplibrary_osx.sh* |
| 59 | + |
| 60 | +These scripts are just examples, they represent what I had to do to get my environment to work correctly, they will need to be edited to work in your environment. |
| 61 | + |
| 62 | +The library directories must be in place before building the *p4bridge* project. |
| 63 | + |
| 64 | +## Getting to know your subprojects |
| 65 | + |
| 66 | +### Building the **p4bridge DLL** |
| 67 | + |
| 68 | +The p4bridge DLL is required by `P4API.NET` and is a C++ project built by cmake. |
| 69 | + |
| 70 | +The same p4bridge DLL will work in both .NET Core and .NET Framework Assemblies. |
| 71 | + |
| 72 | +The source and build instructions for the bridge DLL is in the *p4bridge* subdirectory. |
| 73 | + |
| 74 | + [P4Bridge.md](p4bridge/P4Bridge.md) |
| 75 | + |
| 76 | +### Building and running the **Bridge-Unit-Test** |
| 77 | + |
| 78 | +The bridge-unit-test is a C++ project which provides a test suite for the p4bridge. |
| 79 | +The source, build and configuration instructions for these tests is in the *p4bridge-unit-test* subdirectory. |
| 80 | + |
| 81 | + [BridgeUnitTest.md](p4bridge-unit-test/BridgeUnitTest.md) |
| 82 | + |
| 83 | +### Building and running the **p4bridgeStressTest** |
| 84 | + |
| 85 | + The p4bridgeStressTest is a C++ project which provides a performance test for the p4bridge. The source and instructions for this test is in the p4bridgeStressTest subdirectory. |
| 86 | + |
| 87 | + [p4bridgeStressTest.md](p4bridgeStressTest/p4bridgeStressTest.md) |
| 88 | + |
| 89 | +### Building `P4API.NET` |
| 90 | + |
| 91 | +**IMPORTANT!** - The C++ bridge must have already been built before building P4API.NET. |
| 92 | + |
| 93 | +Make sure you have an updated .NET 6.0 SDK (or better) installed for your platform. |
| 94 | +download from here: [Microsoft .NET Downloads](https://dotnet.microsoft.com/download) |
| 95 | + |
| 96 | +in the p4api.net root folder run |
| 97 | +`dotnet build p4apicore.net.sln` |
| 98 | + |
| 99 | + This will create The .NET DLL in `p4api.net\bin\Debug\net60\p4api.net.dll`, `p4api.net\bin\Debug\net462\p4api.net.dll`, `p4api.net\bin\Debug\netstandard2.0\p4api.net.dll` |
| 100 | + And the Unit test in `\p4api.net-unit-test\bin\Debug\net60\p4api.net-unit-test.dll`, `\p4api.net-unit-test\bin\Debug\net462\p4api.net-unit-test.dll`, `\p4api.net-unit-test\bin\Debug\netstandard2.0\p4api.net-unit-test.dll` |
| 101 | + It will also copy the p4bridge.dll from the appropriate place in the ../p4bridge output into the default output directory. |
| 102 | + |
| 103 | + On Windows, you can specify a specific Configuration and Platform with parameters: |
| 104 | + `dotnet build p4apicore.net.sln -c Release -p:Platform=x86` |
| 105 | + |
| 106 | + On Windows, if no Platform is specified the default is 'x64'. |
| 107 | + On Windows, If no Configuration is specified the default is 'Debug'. |
| 108 | + |
| 109 | +As part of the P4API.NET project build, the (previously build) p4bridge DLLs are copied |
| 110 | +into proper runtime locations. |
| 111 | + |
| 112 | +### Running `P4API.NET Unit Test` |
| 113 | + |
| 114 | +* Using the **dotnet** command, in the *p4api.net* root folder run: |
| 115 | +`dotnet test p4apicore.net.sln` |
| 116 | + |
| 117 | +> Filter on the dotnet framework to run upon |
| 118 | +>> `dotnet test p4apicore.net.sln -f net60` |
| 119 | +> |
| 120 | +> Filter on the specific test to run |
| 121 | +>> `dotnet test p4apicore.net.sln -f net60 --filter TestName` |
| 122 | +
|
| 123 | + |
| 124 | +* **Visual Studio 2019** can be used to debug the .NET unit tests if you are running in Windows. |
| 125 | +Open p4apicore.net.sln, then use the Test Explorer Window to run and manage the tests. |
| 126 | +One unique feature of the VS2019 debugger is that it makes it possible to debug both .NET C# and the P4BRIDGE C++ in the same session. |
| 127 | + |
| 128 | +* **JetBrains Rider** can also be used to debug the .NET unit tests on all platforms, just open p4apicore.net.sln and the Unit Tests will show up in the Unit Test Explorer window. |
| 129 | +Unfortunately, you cannot debug through the C++ code using Rider. |
| 130 | + |
| 131 | +### Creating a nuGet package |
| 132 | + |
| 133 | +1. This only works on WINDOWS with DOTNET CORE so far. |
| 134 | +2. Build the four varieties of p4bridge first |
| 135 | +3. `dotnet pack p4apicore.net.sln` |
| 136 | + |
| 137 | +This will create an Assembly DLL in *.\bin\p4api.net\bin\Debug\net6.0\p4api.net.dll* |
| 138 | +and a nuget package in: |
| 139 | +*p4api.net\bin\Debug\p4api.net.VERSION.nupkg* |
| 140 | + |
| 141 | +### Deploy the nuget package for testing |
| 142 | + |
| 143 | +Deploy this package to a local test repository with: |
| 144 | +`nuget add c:\dev\p4dotnetdev\p4api.net\p4api.net\bin\Debug\p4api.net.2021.2.xxx.yyyy.nupkg -Source C:\dev\local-nuget` |
| 145 | + |
| 146 | +### List packages in the local test repository |
| 147 | + |
| 148 | +`nuget list -Source c:\dev\local-nuget -PreRelease p4api.net` |
| 149 | +returns: *2021.2.xxx.yyyy* |
0 commit comments