Entitas icon indicating copy to clipboard operation
Entitas copied to clipboard

How to setup Entitas in pure C# project?

Open benzsuankularb opened this issue 5 years ago • 24 comments

Hi,

I have some questions about setting up Entitas in pure C# project.


  1. My component was not generated by Jenny.
    1. New project and add references to Entitas.dll and Entitas.CodeGeneration.Attributes.dll
    2. Extract Jenny.zip to project folder.
    3. Run jenny new Entitas.properties then jenny auto-import -s and choose all roslyn.
    4. Fix DesperateDevs.CodeGeneration.Plugins.ProjectPath to be MyProj.csproj
    5. Add PositionComponent : IComponent file to /EntitasPure folder.
[Game]
public sealed class PositionComponent : IComponent
{
   public float x;
   public float y;
}
  1. Run jenny server
  2. Run jenny client gen

Now everything are generated but nothing about Position component generated for me. I'm not sure what I'm missed? Maybe we should add this scenario to the Wiki.

Entitas 1.8.2 from the AssetStore


  1. What's the point of Jenny server. Why don't just use jenny generate instead of the server?

Thanks :)

benzsuankularb avatar Oct 06 '18 09:10 benzsuankularb

My Entitas.properties

Jenny.Ignore.Keys = 
Jenny.SearchPaths = Jenny/Jenny/Plugins/DesperateDevs, \
                    Jenny/Jenny/Plugins/Entitas, \
                    Jenny/Jenny/Plugins/Entitas.Roslyn

Jenny.Plugins = DesperateDevs.CodeGeneration.Plugins, \
                DesperateDevs.CodeGeneration.Unity.Plugins, \
                Entitas.CodeGeneration.Plugins, \
                Entitas.Roslyn.CodeGeneration.Plugins, \
                Entitas.VisualDebugging.CodeGeneration.Plugins

Jenny.PreProcessors = DesperateDevs.CodeGeneration.Plugins.ValidateProjectPathPreProcessor, \
                      DesperateDevs.CodeGeneration.Plugins.TargetFrameworkProfilePreProcessor

Jenny.DataProviders = Entitas.CodeGeneration.Plugins.ContextDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.CleanupDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.ComponentDataProvider, \
                      Entitas.Roslyn.CodeGeneration.Plugins.EntityIndexDataProvider

Jenny.CodeGenerators = Entitas.CodeGeneration.Plugins.ComponentContextApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentEntityApiInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentLookupGenerator, \
                       Entitas.CodeGeneration.Plugins.ComponentMatcherApiGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextAttributeGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextMatcherGenerator, \
                       Entitas.CodeGeneration.Plugins.ContextsGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityGenerator, \
                       Entitas.CodeGeneration.Plugins.EntityIndexGenerator, \
                       Entitas.CodeGeneration.Plugins.EventEntityApiGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenerComponentGenerator, \
                       Entitas.CodeGeneration.Plugins.EventListenertInterfaceGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemGenerator, \
                       Entitas.CodeGeneration.Plugins.EventSystemsGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemGenerator, \
                       Entitas.Roslyn.CodeGeneration.Plugins.CleanupSystemsGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.ContextObserverGenerator, \
                       Entitas.VisualDebugging.CodeGeneration.Plugins.FeatureClassGenerator

Jenny.PostProcessors = DesperateDevs.CodeGeneration.Plugins.AddFileHeaderPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.CleanTargetDirectoryPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.MergeFilesPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.NewLinePostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.WriteToDiskPostProcessor, \
                       DesperateDevs.CodeGeneration.Plugins.ConsoleWriteLinePostProcessor

Jenny.Server.Port = 3333
Jenny.Client.Host = localhost
DesperateDevs.CodeGeneration.Plugins.ProjectPath = MyProj.csproj
Entitas.CodeGeneration.Plugins.Contexts = Game, \
                                          Input

Entitas.CodeGeneration.Plugins.IgnoreNamespaces = false
DesperateDevs.CodeGeneration.Plugins.TargetDirectory = ./

jenny doctor said happy coding.

benzsuankularb avatar Oct 06 '18 13:10 benzsuankularb

I will add, that Jenny have bug with pure C# projects: It is only works if your generated output folder is in Assets folder root, even if you change this paths in *.properties file

kkohno avatar Oct 06 '18 14:10 kkohno

change TargetDirectory sring in your .properties file as follows, and it will works: DesperateDevs.CodeGeneration.Plugins.TargetDirectory = Assets

also you can make following bat file to generate without servers and unity: pushd %~dp0 .\Jenny\Jenny.exe gen popd

kkohno avatar Oct 06 '18 14:10 kkohno

@kkohno

I will add, that Jenny have bug with pure C# projects: It is only works if your generated output folder is in Assets folder root, even if you change this paths in *.properties file

Nah, Still not work. But maybe it's a bug like you said.

also you can make following bat file to generate without servers and unity: pushd %~dp0 .\Jenny\Jenny.exe gen popd

Yeah, But what's the point of server then?

benzsuankularb avatar Oct 06 '18 14:10 benzsuankularb

issues 706 No help with this.


Similar issues:

issues 803 I think the same issue here. But that's in Unity. From @sschmid mentioned there.

  1. Correct project name for sure.
  2. My component inherited Entitas.IComponent.
  3. I'm not in Unity but I've tried both .netstandard2.0 and .netframework4.7.
  4. If I remove <TargetFramework>netstandard2.0</TargetFramework> project will unable to restore.

issues 759 Maybe look like the same issue but I don't know why he can get it worked on .netframework.

issue 798 issue 798 No info. But maybe the same problem.

Pretty severe somehow I think.

benzsuankularb avatar Oct 06 '18 15:10 benzsuankularb

@sschmid I've removed the repo. Apologize for that, I didn't mean to do it.

Here's the new sample repo. Please investigate this, I can't continue working on the project.

benzsuankularb avatar Oct 07 '18 01:10 benzsuankularb

What's the point of Jenny server. Why don't just use jenny generate instead of the server?

The server is for caching purpose. So running the server will result in faster generation process with the second run. You can also use Jenny alone, but then without caching and every run will take longer.

TheHacky avatar Oct 07 '18 10:10 TheHacky

@benzsuankularb I added a new wiki page with a step by step guide, how to set up a C# only project with Entitas

https://github.com/sschmid/Entitas-CSharp/wiki/Entitas-pure-C%23

I hope this helps

sschmid avatar Oct 09 '18 17:10 sschmid

I will dump a few images here, so I can reference them in the wiki

entitaspure-jenny entitaspure-gen entitaspure-done entitaspure-folders

sschmid avatar Oct 09 '18 17:10 sschmid

What's the .NET version of the project?

sschmid avatar Oct 09 '18 19:10 sschmid

netstandard2.0

benzsuankularb avatar Oct 09 '18 19:10 benzsuankularb

@kkohno

Jenny have bug with pure C# projects

Not quite sure what you mean. You can specify any folder.

sschmid avatar Oct 09 '18 19:10 sschmid

@benzsuankularb As described in the wiki https://github.com/sschmid/Entitas-CSharp/wiki/Entitas-pure-C%23

here's a working project https://github.com/sschmid/EntitasPure

sschmid avatar Oct 13 '18 17:10 sschmid

@sschmid .framework is OK but still not working with .netstandard and .netcore.

I think it's about <Compile Include="..."> not working on .netstandard.

I've updated 100% as you describe in the wiki. https://github.com/benzsuankularb/EntitasIssue806

benzsuankularb avatar Oct 13 '18 19:10 benzsuankularb

Installed dotnet 2. First impression, csproj works differently. Source files are not listed but recognized. To fix compilation, I removed DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor to prevent <Compile Include="...">

Have to investigate further. My guess, since the project file is empty, no components are found

sschmid avatar Oct 13 '18 20:10 sschmid

Duplicate 'Compile' items were included. The .NET SDK includes 'Compile' items from your project directory by default. You can either remove these items from your project file, or set the 'EnableDefaultCompileItems' property to 'false' if you want to explicitly include them in your project file. For more information, see https://aka.ms/sdkimplicititems

Try setting 'EnableDefaultCompileItems' property to 'false'

sschmid avatar Oct 13 '18 20:10 sschmid

I readded DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor and added

<EnableDefaultCompileItems Condition=" '$(EnableDefaultCompileItems)' == '' ">false</EnableDefaultCompileItems>

to the projects <PropertyGroup> and readded Program.cs and HealthComponent.cs Code Generation and updating the project works now, but still no component generated

sschmid avatar Oct 13 '18 20:10 sschmid

Seems to be an issue with the netcore csproj, works with .NET csproj

sschmid avatar Oct 13 '18 21:10 sschmid

This works as a workaround for net core solutions:

Add a new .NET 4.x project for all your components within your solution with a standard jenny setup and reference this project in you net core project. All components and generated code will be in the .NET 4.x project, all your production code in the net core project

sschmid avatar Oct 13 '18 21:10 sschmid

If components use custom datatypes as fields, those obviously have to be in that project too.

sschmid avatar Oct 13 '18 21:10 sschmid

Thanks a lot. I forget about having reference from netcore to net4.x.

benzsuankularb avatar Oct 14 '18 02:10 benzsuankularb

Same issue, my project is <TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>, it doesn't generate Component code. Now I use mklink to link all code files to a Unity project to generate codes, that works fine.

Zonciu avatar Nov 17 '18 17:11 Zonciu

Can also be done without linking with creating a dummy 4.7.1 csproj file with ItemGroup: <Compile Include="path/Components/**/*.cs" />. You can also disable generate csproj file in jenny settings. Much cleaner and more simple solution.

hegi25 avatar Feb 18 '19 13:02 hegi25

  1. Create a .NET 4.7.1 or greater project Generator, extract Jenny folder into Generator (do not use .Net Core project and set <TargetFramework>NET471</TargetFramework>, that won't work)

  2. Include your folder like this:

<Compile Include="..\PureCSharpProject\Components\**\*.cs" />
<Compile Include="..\PureCSharpProject\Generated\**\*.cs" />
  1. following Jenny configuration in Entitas Pure C#

  2. set output directory, disable update csproj

Remove

DesperateDevs.CodeGeneration.Plugins.UpdateCSProjPostProcessor

Set

DesperateDevs.CodeGeneration.Plugins.ProjectPath = Generator.csproj
DesperateDevs.CodeGeneration.Plugins.TargetDirectory = ..\PureCSharpProject
  1. execute Jenny in Generator directory, like E:\MyGame\src\Generator> Jenny\Jenny.exe gen

Zonciu avatar Apr 19 '19 13:04 Zonciu

Here's a sample Entitas project as a dotnet console app using .NET 6.0 and .NET Standard 2.1, including a working Jenny setup:

Entitas-Standalone

Also see announcement: Jenny is now open-source https://github.com/sschmid/Entitas/discussions/1008

sschmid avatar Sep 09 '22 21:09 sschmid