Skip to content

Netstandard setup

Stanislav Silin edited this page Jun 3, 2023 · 4 revisions

The setup for NetStandard is largely similar to that of .NET Core, with a few additional steps. Specifically, you will need to install the JSON package and enable .NET Standard compatibility.

Follow these steps to create a NetStandard2.1 library and add ZeroQL:

# Begin by adding a tools manifest
dotnet new tool-manifest 

# Install the ZeroQL command-line interface (CLI)
dotnet tool install ZeroQL.Cli 

# Create a class library
dotnet new classlib -f netstandard2.1 -o QLClient 

# Navigate into the new class library
cd QLClient

# Add ZeroQL to the class library
dotnet add package ZeroQL 
# Include the JSON serializer
dotnet add package System.Text.Json
# Retrieve the schema
dotnet zeroql schema pull --url http://localhost:10000/graphql
# Initialize ZeroQL configuration 
dotnet zeroql config init
# Generate the client
dotnet zeroql generate -c ./zeroql.json

Next, open the QLClient.csproj file in your IDE. You may encounter some compilation errors due to issues in Generate/GraphQL.g.cs.

To resolve these errors:

  1. Open the csproj file in a text editor and add the line <LangVersion>latestmajor</LangVersion> within the first PropertyGroup section. This action should eliminate most of the errors, except for one - the missing ModuleInitializer class.

  2. Open the zeroql.json file and insert the option "netstandardCompatibility": true.

  3. Regenerate the client using the following command:

dotnet zeroql generate -c ./zeroql.json

With this, all the compilation errors should be resolved, and you should be able to use ZeroQL. This setup process has been successfully tested with .NET Framework and Xamarin applications.