--- myst: substitutions: image1: |- ```{image} /img/getting_started/add_reference_to_vs.png :width: 1000px ``` image2: |- ```{image} /img/getting_started/helloworldpackage.png :width: 400px ``` --- # Using the .NET library To use the .NET library you first need to [install]() powerLoad (bcpToolkit) on your development machine.\ The library contains all the [API's]() to create your own BCP-package. It requires your project targeting at least **.NET framework 4.7** ! :::{dropdown} 1. Reference the bcpDevKit assembly In Visual Studio right-click on *References* and click "*Add References*".\ Search for the assembly "*bcpDevKit*" in Assemblies-tab and add it to your project. {{ image1 }} The assembly will be referenced from the **GAC**, therefore set *"Copy Local"* to *"false"*. ::: :::{dropdown} 2. Create the BcpServiceBuilder and set the PackageLocation In order to gain access to the bcpDevKit API's, following **namespaces** should be imported: ```csharp using bcpDevKit; using bcpDevKit.Entities; ``` Root entry point is the class [BcpServiceBuilder](): ```csharp var bcpSvcBuilder = new BcpServiceBuilder(); ``` First we set the target BCP [Version]() for which the package should be created: ```csharp bcpSvcBuilder.Version = BcpVersion._2024; ``` Then we set the [PackageLocation](), where the Package should be exported to: ```csharp bcpSvcBuilder.SetPackageLocation("C:\\Temp\\HelloWorldPackage"); ``` ::: :::{dropdown} 3. Build the BcpService and start working After preparing the BcpServiceBuilder with the desired settings we can now [build]() the BcpService: ```csharp var bcpService = bcpServiceBuilder.Build(); ``` The [BcpService]() gives us access to all the functionality for creating a importable BCP package.\ We can start to add Files and Items to our package: ```csharp var file = bcpService.FileService.AddFileWithIteration("$/HelloWorldFiles/Hello.iam", @"C:\HelloWorldFiles\Hello.iam"); var item = bcpService.ItemService.AddItem("999", "World", "Title 999", "Desc 999"); ``` ::: :::{dropdown} 4. Create the BCP package Finally we can create and export our BCP package to our package location by calling [Flush]() on the BcpService: ```csharp bcpService.Flush(); ``` After calling the function you can find the created package in your packageDirectory: {{ image2 }} The package can now be used to import the data into Vault. ::: :::{admonition} Install powerLoad (bcpToolkit) on customer machine :class: warning When shipping the binaries of your project to the customer, **also the customers machine requires a powerLoad (bcpToolkit) installation**.\ Therefore delivering the *bcpDevKit* assembly within your project should be avoided, so that new bcpDevKit versions can continue to be easily [updated]() at the customer's site. ::: See the **complete example**: ```{code-block} csharp :emphasize-lines: 11 :linenos: using System; using bcpDevKit; using bcpDevKit.Entities; namespace HelloWorldPackage { class Program { static void Main(string[] args) { var bcpSvcBuilder = new BcpServiceBuilder(); bcpSvcBuilder.Version = BcpVersion._2024; bcpSvcBuilder.SetPackageLocation("C:\\Temp\\HelloWorldPackage"); var bcpService = bcpSvcBuilder.Build(); var file = bcpService.FileService.AddFileWithIteration("$/HelloWorldFiles/Hello.iam", @"C:\HelloWorldFiles\Hello.iam"); var item = bcpService.ItemService.AddItem("999", "World", "Title 999", "Desc 999"); bcpService.Flush(); } } } ```