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

NuGetForUnity CLI Package Generates Incorrect/missing .meta files #637

Open
Reag opened this issue Apr 8, 2024 · 2 comments
Open

NuGetForUnity CLI Package Generates Incorrect/missing .meta files #637

Reag opened this issue Apr 8, 2024 · 2 comments

Comments

@Reag
Copy link

Reag commented Apr 8, 2024

Description

The purpose of the NuGetForUnity CLI tool is to act as a pre build step for automated pipelines. However, when it downloads a DLL that includes a Roslyn Analyzer (Especially if said DLL is for code gen), said DLL will not receive a .meta file that includes the correct label. This means that the DLL will never perform its code gen in the automated pipeline.

In the normal editor, this isn't a problem, as part of the startup process includes a NuGet Restore that will build these meta files and tag them. However, in an automated pipeline, this step never seems to actually occur. If you perform

nugetforunity restore <PROJECTPATH> //Nuget Restore
unity-editor -quit        -batchmode -ignoreCompilerErrors ... //Run the project once, ignoring compilation errors. Should CodeGen
unity-editor -runTests -batchmode .... //Run tests!

It will fail to perform the required code gen and the .meta files will not have the correct label. Performing the same set of operations works fine if the editor is not in batch mode.

@JoC0de
Copy link
Collaborator

JoC0de commented Apr 19, 2024

Hi @Reag
Thanks for creating the issue and sorry for the delay.
I created the CLI exactly for the reason that the batch mode didn't perform the restore operation at the correct point in time. But I never tested the .meta manipulation we als do in the restore/import. I think the main causes of the problem is that unity imports the dlls downloaded by the CLI before the NuGeForUnity plugin is imported by the package manager. One possible workaround would be to start unity twice, at least I think it helped to do the restore without the CLI. At least for the issue with Roslyn Analyzers it should be possible to duplicate the feature so the CLI also sets the correct .meta attributes.

@AlanLiu90
Copy link

AlanLiu90 commented Jan 14, 2025

Hi,

We tried to use NuGetForUnity recently and found it doesn't work well with source generator in Unity 2022.

Here is a scenario:

  1. A project uses a nupkg contaning source generator and contains some code based on the code generated by that source generator
  2. Someone clones the project and launches Unity Editor.
  3. Since the nupkg doesn't exist locally, the compilation fails and then Unity enters safe mode. The nupkg cannot be restored. (Although safe mode can be skipped, it may cause asset pre/post processors to not run properly)

Even when NuGetForUnity.Cli is used to restore the nupkg before launching Unity, the project still can't be opened correctly because Unity generates .meta file for the source generator without RoslynAnalyzer label and other settings.

I looked into the code of NuGetForUnity.Cli, there is a FixRoslynAnalyzerImportSettings method for generating .meta files for analyzer/source generator, but it only works for Unity 2021 or earlier versions. After changing the method to make it run for Unity 2022, the project mentioned above can be opened correctly in Unity Editor (executing NuGetForUnity.Cli.exe restore before launching Unity Editor).

Should FixRoslynAnalyzerImportSettings also run for Unity 2022 and later?

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

3 participants