How-to guide·Install.NET

.NET

Install the .NET SDK (BIMworks.Sdk, generated from the OpenAPI) or the classic BIM.works_SDK package from nuget.org or the BIM.works feed, including pre-release versions, and check that it connects.

For .NET developers. There are two .NET SDKs, both public on nuget.org, so no registry credentials are needed (SDKs compares them):

  • the .NET SDK, BIMworks.Sdk, generated from the OpenAPI document. Use it for a new integration; its reference is .NET SDK.
  • the classic .NET SDK, BIM.works_SDK, the hand-written client of the task API; its reference is Classic .NET SDK, and .NET quick start is a first program.

The .NET SDK#

BIMworks.Sdk targets .NET 8 and .NET Standard 2.0, and brings Microsoft.Extensions.Hosting and .Http with it. Its examples are console programs for the .NET 8 SDK:

Shell#
dotnet new console -n BimWorksExample
cd BimWorksExample
dotnet add package BIMworks.Sdk --version 3.0.0-beta.192

To check the installation, put the program below in Program.cs and dotnet run it; it logs in with your API token and prints the UUID of your root node. Every example of the .NET SDK has these four steps (reference/sdk/dotnet#example-shape).

using System.Text.Json;
using BIMworks.Sdk.Api;
using BIMworks.Sdk.Client;
using BIMworks.Sdk.Extensions;
using BIMworks.Sdk.Model;
using Microsoft.Extensions.DependencyInjection;

// 1. Connect to BIM.works and log in with your API token
IServiceProvider Connect(string bearer)
{
    var services = new ServiceCollection();
    services.AddApi(options =>
    {
        options.AddTokens(new BearerToken(bearer));
        options.AddApiHttpClients(http =>
        {
            http.BaseAddress = new Uri("https://bim.works" + "/openapi");
            http.Timeout = Timeout.InfiniteTimeSpan;
        });
    });
    return services.BuildServiceProvider();
}
var login = await Connect("").GetRequiredService<IAuthApi>().LoginWithApiTokenAsync(new LoginWithApiTokenRequest("<your API token>"));
var auth = login.Ok()?.Auth ?? throw new HttpRequestException(login.RawContent, null, login.StatusCode);
var client = Connect(auth.Base64);
var json = client.GetRequiredService<JsonSerializerOptionsProvider>().Options;

// 2. The request
// (GetRootNodeUuid takes no request)

// 3. The call
var response = await client.GetRequiredService<IFsApi>().GetRootNodeUuidAsync();

// 4. The result
var result = response.Ok() ?? throw new HttpRequestException(response.RawContent, null, response.StatusCode);
Console.WriteLine(JsonSerializer.Serialize(result, json));

Pre-release versions and the BIM.works feed work as for the classic package below; map BIMworks.Sdk to the feed in the same way.

The classic SDK#

Before you start#

  • A project that targets .NET Standard 2.0 or anything that consumes it: .NET Core 2.0 and later, .NET 5 and later, or .NET Framework 4.6.1 and later.
  • The package's one dependency, System.Text.Json 8.0.5 or newer, is pulled in by NuGet.

1. Add the package#

The package id is BIM.works_SDK. Use the version that matches your BIM.works server (the version pill at the top of this page is the server's); pick one of the three ways:

Shell#
dotnet add package BIM.works_SDK --version 3.0.0-beta.192
Text#
Install-Package BIM.works_SDK -Version 3.0.0-beta.192
XML#
<PackageReference Include="BIM.works_SDK" Version="3.0.0-beta.192" />

2. Allow pre-release versions#

Beta versions carry a -b.<n> suffix (3.0.0-b.38), and NuGet hides those unless you ask for them:

  • Visual Studio: tick Include prerelease in Manage NuGet Packages.
  • Package Manager Console: add -IncludePrerelease to Install-Package and Update-Package.
  • dotnet CLI: add --prerelease to dotnet add package, or name the exact version as above.
Note

The package can also be downloaded as a .nupkg from a BIM.works instance that has the DOWNLOAD_BUILDS feature, see Downloads. Use it only for machines without access to nuget.org.

3. Or take it from the BIM.works feed#

nuget.org is the main place for the package. If you would rather take every BIM.works SDK from one place with one set of credentials, the same versions are also on the private feed https://nuget.bim.works/v3/index.json. Your company portal has the credentials, or ask support@bimbase.nl.

Three things differ from nuget.org:

  • A project takes BIM.works_SDK from one of the two, never from both. nuget.org signs its copy of every package, so the two files differ, and the hash in a packages.lock.json belongs to the source it was made with.
  • Map the package to the feed. The SDK's dependency (System.Text.Json) still comes from nuget.org, so both sources are configured. The packageSourceMapping below makes BIM.works_SDK always come from the BIM.works feed; without it, NuGet takes it from whichever source answers first.
  • Switching sources means a new lock file. Moving a project from nuget.org to the feed, or back, needs dotnet restore --force-evaluate once.

Put a nuget.config next to your solution:

XML#
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="bimworks" value="https://nuget.bim.works/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <bimworks>
      <add key="Username" value="[your username]" />
      <add key="ClearTextPassword" value="[your password]" />
    </bimworks>
  </packageSourceCredentials>
  <packageSourceMapping>
    <packageSource key="bimworks"><package pattern="BIM.works_SDK" /></packageSource>
    <packageSource key="nuget.org"><package pattern="*" /></packageSource>
  </packageSourceMapping>
</configuration>

NuGet encrypts stored passwords on Windows only, hence ClearTextPassword; keep the file out of version control. On a build server, set the environment variable NuGetPackageSourceCredentials_bimworks to Username=[your username];Password=[your password] instead of the packageSourceCredentials block. Then add the package as in step 1.

Check#

With the classic SDK, create a factory, log in anonymously and print the server's version. This needs no API token.

.NET#
using System;
using BIM.works_SDK;

using (BimWorksClientFactory factory = new BimWorksClientFactory(new Uri("https://bim.works")))
using (BimWorksClient client = factory.CreateAnonymousClient())
{
    Console.WriteLine(client.Info.GetApplicationVersion());
}

It prints a JSON object with the server's version. CreateAnonymousClient is on the factory (Classic .NET SDK) and GetApplicationVersion on Info. Next: Log in with an API token.