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

[Source Generator] Unable to disable multiple source generators using GodotDisabledSourceGenerators property #91999

Open
Panthr75 opened this issue May 15, 2024 · 1 comment

Comments

@Panthr75
Copy link

Tested versions

Godot

Based on looking at the github, all versions have this bug

  • 4.2.1

Visual Studio

  • 17.9.0
  • 17.9.7

System information

Windows 10 - x64 - vs17.9.7

Issue description

For some reason C# source generators attempting to access global config properties that have a value with a ; in them result in said value getting truncated.

For example:

<Project Sdk="Godot.NET.Sdk/4.2.1">
  <!-- ... -->

  <PropertyGroup>
    <GodotDisabledSourceGenerators>GodotPluginsInitializer;ScriptPathAttribute</GodotDisabledSourceGenerators>
  </PropertyGroup>
</Project>

When the source generators run, they only see the value GodotPluginsInitializer for the GodotDisabledSourceGenerators property even though the generated GeneratedMSBuildEditorConfig.editorconfig has build_property.GodotDisabledSourceGenerators set to GodotPluginsInitializer;ScriptPathAttribute

I wrote my own Source Generator to verify.

This is what's inside the GeneratorExecutionContext:
image

But note this is the generated GeneratedMSBuildEditorConfig.editorconfig that is created inside the obj folder:
image

The values of GodotDisabledSourceGenerators in the source generator conflict with the values inside the editor config.

To fix this issue, the separator can be changed from a ; to a ,.

Steps to reproduce

  1. Edit the csproj file of a C# Godot Project to include the following line in between a <PropertyGroup> tag in Visual Studio 2022:
<GodotDisabledSourceGenerators>GodotPluginsInitializer;ScriptPathAttribute</GodotDisabledSourceGenerators>
  1. Add the following class to the project:
using Godot;

public partial class DummyClass : Resource
{
}
  1. Build the C# Godot Project
  2. Inspect the C# Godot Project with ILSpy or an equivalent
  3. Notice the GodotPlugins.Game was not generated
  4. Decompile DummyClass
  5. DummyClass has the ScriptPathAttribute on it, even though the ScriptPathAttribute source generator was meant to be disabled.

Minimal reproduction project (MRP)

N/A

@raulsntos
Copy link
Member

In editorconfig ; is the comment character, so everything after it is ignored. This is unfortunate since in MSBuild ; is the separator character.

In editorconfig/specification#31 the editorconfig specificaition was updated to clarify that ; and is only a comment when it's at the beginning of the line, thus allowing MSBuild to use ; as a separator character.

However Roslyn still needs to be updated to follow the updated specification:

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

No branches or pull requests

2 participants