NEKERAFA / clingo-cs

A C# bindings of Clingo library
MIT License
3 stars 0 forks source link

adding clingo-cs to a C# project? #18

Open d-vyd opened 2 years ago

d-vyd commented 2 years ago

Hi Rafael,

Thank you for all your work making clingo-cs! I'm very interested in combining C# and Clingo. When clingo-cs is added to a project, will I then be able to follow the Python API example? Something like:

using Clingo-cs; var ctl = clingo.Control() ctl.add("base", [], "p(@id(10)). q(@seq(1,2))."); ctl.ground([("base", [])], context=Context());

I've taken the following steps:

  1. downloaded clingo-cs from github as ZIP
  2. downloaded clingo-5.5.1, renamed it to "clingo", and placed it in clingo-cs-main
  3. created clingo\build\win and clingo\build\linux
  4. .\build.ps1 (success!)
  5. dotnet build --configuration Debug (partial success?)

clingo-cs-main\src\Clingo_cs\bin\Debug contains: Clingo_cs.0.1.0.nupkg (11kb) net6.0 (directory)

The net6.0 directory contains: Clingo_c.dll (10kb) Clingo_c.pdb (12kb) Clingo_cs.deps.json (1kb) Clingo_cs.dll (17kb) Clingo_cs.pdb (17kb) ref (directory)

The ref directory contains: Clingo_cs.dll (10kb)

In Visual Studio, I created a package source entry for clingo-cs-main\src\Clingo_cs\bin\Debug and when I open Nuget and use this source, I see the option to install a single package:

Clingo_cs by Rafael Alcalde Azpiazu A C# bindings to the clingo library.

When I select that package, I see the following errors:

Here are the detailed results of the build:

PS D:\Documents\Programming\CSharp\clingo-cs-main> dotnet build --configuration Debug Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Copyright (C) Microsoft Corporation. All rights reserved.

Determining projects to restore... All projects are up-to-date for restore. Clingo_c -> D:\Documents\Programming\CSharp\clingo-cs-main\src\Clingo_c\bin\Debug\net6.0\Clingo_c.dll C:\Program Files\dotnet\sdk\6.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : Could not find a part of the path 'D:\Documents\Programming\CSharp\clingo-cs-main\clingo\build\linux\bin'. [D:\Documents\Programming\CSharp\clingo-cs-main\src\Clingo_c\Clingo_c.csproj] Clingo_cs -> D:\Documents\Programming\CSharp\clingo-cs-main\src\Clingo_cs\bin\Debug\net6.0\Clingo_cs.dll Clingo_cs.Tests -> D:\Documents\Programming\CSharp\clingo-cs-main\tests\bin\Debug\net6.0\Clingo_cs.Tests.dll

Build FAILED.

C:\Program Files\dotnet\sdk\6.0.101\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : Could not find a part of the path 'D:\Documents\Programming\CSharp\clingo-cs-main\clingo\build\linux\bin'. [D:\Documents\Programming\CSharp\clingo-cs-main\src\Clingo_c\Clingo_c.csproj] 0 Warning(s) 1 Error(s)

NEKERAFA commented 2 years ago

Hi @d-vyd,

Firstly, yes, the aim of this proyect is to create an API that looks like Python Clingo. Still, as I am doing it by hand, it is not complete, so for a real scenario things may be missing (in the example you gave the context is not supported yet). For updated API, you can check github page of the proyect: https://nekerafa.github.io/clingo-cs/api/ClingoSharp.html

About the second part, beause another goal was to created a mod for Cities: Skylines that combines with clingo (you can check the another repository for an example of use of this API: https://github.com/NEKERAFA/CS-IndustryLP), I have not tested the if the latest nuget packages work in a real environment. As a temporary solution I recommend that you include the project as a reference:

git submodule add https://github.com/NEKERAFA/clingo-cs.git
git submodule update --init --recursive

In the csproj:

<ItemGroup>
<ProjectReference Include="clingo-cs/src/Clingo_cs/Clingo_cs.csproj" />
</ItemGroup>

Or using command line:

dotnet add reference clingo-cs/src/Clingo_cs/Clingo_cs.csproj
d-vyd commented 2 years ago

Thank you. I'll give that a try!