Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch automatic Ontologies.g.cs generation off #14

Open
IgorKaplya opened this issue Nov 4, 2021 · 5 comments
Open

Switch automatic Ontologies.g.cs generation off #14

IgorKaplya opened this issue Nov 4, 2021 · 5 comments

Comments

@IgorKaplya
Copy link

The autogeneration behavior produces a lot of pitfalls during CI/CD pipelines, as follows:

##[error]Domain\OntologyResources\Focus.cs(13,1): error : R# Ambiguous reference:
OymOntology.oym
OymOntology.oym

Though I definitely know that my Ontologies.g.cs is consistent and OymOntology.oym class was not ambiguous when pushed to Git.

Steps to reproduce:

  1. Download and unzip free ReSharper command line tools: https://www.jetbrains.com/resharper/download/#section=commandline
  2. run command from unpacked folder (change path to solution of yours):

inspectcode "d:\trinity-rdf-examples\core-example\core-example.csproj" /o:"output.xml" --properties:Configuration=Release --no-build --verbosity=info

  • Expected: Produced output.xml shouldn't contain any CSharpErrors (otherwise code is considered faulty and not accepted as valid PR),
  • Actual: Many errors like
     <Issue TypeId="CSharpErrors" File="ObjectModel\Drug.cs" Offset="1667-1673" Line="37" Message="Ambiguous reference:&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;match" />
     <Issue TypeId="CSharpErrors" File="ObjectModel\Drug.cs" Offset="1910-1916" Line="45" Message="Ambiguous reference:&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;match" />
     <Issue TypeId="CSharpErrors" File="ObjectModel\Drug.cs" Offset="2016-2022" Line="49" Message="Ambiguous reference:&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;  Semiodesk.Example.SCHEMA&#xD;&#xA;match" />

It is very hard to say what exactly causes this issue, I can only assume that R# builds the project and ontologies.g.cs become dirty after that (same command with --verbosity=verbose > output.log contains on a log file:

MsBuild [ProjectModel] Process 26244: Starting ontology generator in d:\work\OYM_files\trinity\trinity-rdf-examples\core-example

Is it possible to switch off auto-generation of Ontologies.g.cs?

@faubulous
Copy link
Collaborator

Not that I am aware of at the moment. But I think it would be a good idea to introduce such an option. The generation is triggered in the following file:

https://github.com/semiodesk/trinity-rdf/blob/master/Trinity/Targets/Semiodesk.Trinity.targets

We need to add a condition here that can be changed in the project settings. I am not to deep into the build system so I currently have to idea on how to implement this.

Another solution would be not to have the ontology generator overwrite the files if they are identical. That should be fairly easy to do.. what do you think?

@faubulous
Copy link
Collaborator

Just saw that the ontology generator reads the project's ontology.config file. We could add an option there to disable the generator:

https://github.com/semiodesk/trinity-rdf/blob/master/Trinity.OntologyGenerator/Program.cs

Not overwriting identical files would probably still not a bad idea, given that some toolchains seem to care about this.

@IgorKaplya
Copy link
Author

Found a workaround for 1.0.3.50 version:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <ontologies namespace="Domain.AutoGeneratedOntologies" >
<!-- Uncomment to enable Ontologies.g.cs auto-generation
    <ontology uri="http://www.w3.org/1999/02/22-rdf-syntax-ns#" prefix="rdf"> <filesource location="Ontologies/rdf.ttl"/> </ontology>
    <ontology uri="http://www.w3.org/2000/01/rdf-schema#" prefix="rdfs"> <filesource location="Ontologies/rdfs.ttl"/> 
-->
  </ontologies>
</configuration>

When ontologies will need an update, I'll be able to handle that:

  • uncomment ontologies.config
  • rebuild solution (new Ontologies.g.cs will be generated)
  • test everything
  • comment ontologies.config

@IgorKaplya
Copy link
Author

@faubulous I would expect some sort of switch in ontology.config to support both modes: auto/manual generation of Ontologies.g.cs. As for auto: everything is left as it is designed. The manual mode would be great to have a command sent directly from the package manager console (as scaffold or add-migration in ef) a simple console app would also be fine.

@faubulous
Copy link
Collaborator

@IgorKaplya Great that you found a workaround! However, adding a switch to ontology.config should not be a big deal and I'll try to add it for the next version of Trinity. Btw. the ontology generator is already a simple console app which is shipped with the NuGet package. It should also work standalone:

https://nuget.info/packages/Semiodesk.Trinity/1.0.3.50

Look for tools/OntologyGenerator.exe. It takes two required arguments:

  • c|config: Path of the config file.
  • g|generate: Path of the ontologies.cs file to generate.

Running OntologyGenerator.exe -c ontology.config -g Ontologies.g.cs should do the trick.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants