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

Need help with Roslyn #1051

Closed
sschmid opened this issue Dec 12, 2022 · 5 comments
Closed

Need help with Roslyn #1051

sschmid opened this issue Dec 12, 2022 · 5 comments

Comments

@sschmid
Copy link
Owner

sschmid commented Dec 12, 2022

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.

  • Context("Test1")
  • Context("Test2")
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

  • The unit test fails and the attribute is Entitas.Context instead of Entitas.Plugins.Attributes.ContextAttribute("Test1")
  • The AttributeClass is ExtendendErrorTypeSymbol instead of NonErrorTypedSymbol
  • Even System attributes like System.Obsolete is not recognized
  • I could fix System attributes by manually adding MetadataReference, but could not fix the Entitas attributes
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")));
  • When compiling the code generator and running it on the test fixtures project, everything works as expected. Only the unit tests are failing?!
  • For sanity reasons, I added a test pointing to the Match-One project where I modified the AssetComponent similar to the test component, and the test passes.
using System;
using Entitas;
using Entitas.Plugins.Attributes;

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

Summary:

  • Code Generator itself works
  • Only unit test fails (?!?)
  • Tests work on Match One (old style csproj)
  • Tests fail on Test Fixtures (sdk style csproj) and symbols are not resolved correctly

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
Copy link
Owner Author

sschmid commented Dec 12, 2022

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

https://github.com/sschmid/RoslynUnitTestIssue

@xtqqksszml
Copy link

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
Copy link
Owner Author

sschmid commented Dec 13, 2022

@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
Copy link
Owner Author

sschmid commented Dec 13, 2022

Solved by adding NuGet.Frameworks package to the test project

sschmid/RoslynUnitTestIssue#1 (comment)

dotnet/roslyn#52954

@sschmid sschmid closed this as completed Dec 13, 2022
@xtqqksszml
Copy link

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

@sschmid sschmid added this to Entitas Jul 2, 2023
@github-project-automation github-project-automation bot moved this to Todo in Entitas Jul 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

2 participants