sschmid / Entitas

Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
MIT License
7.18k stars 1.11k forks source link

Need help with Roslyn #1051

Closed sschmid closed 1 year ago

sschmid commented 1 year ago

Need help with Roslyn

I'm stuck on a roslyn issue and need help.

Setup:

I want to get the ContextAttribute from a component using Roslyn, e.g.

using Entitas;
using Entitas.Plugins.Attributes;

namespace My.Namespace
{
    [Context("Test1"), Context("Test2")]
    public sealed class MyComponent : IComponent
    {
        public string Value;
    }
}

Problem:

The ContextAttribute is not recognized.

I created a branch with a failing unit test to reproduce and help debugging:

More info

project = project.AddMetadataReference(MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location))
    .AddMetadataReference(MetadataReference.CreateFromFile(Path.Combine(ProjectPath, "bin", "Release", "Entitas.dll")))
    .AddMetadataReference(MetadataReference.CreateFromFile(Path.Combine(ProjectPath, "bin", "Release", "Entitas.Plugins.Attributes.dll")));
using System;
using Entitas;
using Entitas.Plugins.Attributes;

[Game, Context("Test"), Obsolete("My Reason")]
public sealed class AssetComponent : IComponent
{
    public string Value;
}

Summary:

Do I need to manually add more project or assembly references? Am I loading the project wrong? Do I somehow run the unit test in a different way as the code generator?

Any help is appreciated!

sschmid commented 1 year ago

I extracted the affected code to a minimal standalone setup that can be tested easily:

https://github.com/sschmid/RoslynUnitTestIssue

xtqqksszml commented 1 year ago

Hi, sschmid. I'm stuck on a roslyn issue too. I was run all tests with Entitas-1.14.2, and I got several errors in Entitas.CodeGeneration.Tests. you can see the picture. Is this the same problem as yours? Were you fixed it? image

sschmid commented 1 year ago

@xtqqksszml yes, that's exactly the issue. Those fail for me too.

I recreated the issue in the minimal project setup mentioned above: https://github.com/sschmid/RoslynUnitTestIssue

Still not sure how to fix it... any help is appreciated

sschmid commented 1 year ago

Solved by adding NuGet.Frameworks package to the test project

https://github.com/sschmid/RoslynUnitTestIssue/issues/1#issuecomment-1348083201

https://github.com/dotnet/roslyn/issues/52954

xtqqksszml commented 1 year ago

@sschmid Thank you. I just tried it again, and It was solved.