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

IncrementalGenerator stopped working in VS 17.11 #74840

Closed
nvborisenko opened this issue Aug 21, 2024 · 1 comment
Closed

IncrementalGenerator stopped working in VS 17.11 #74840

nvborisenko opened this issue Aug 21, 2024 · 1 comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@nvborisenko
Copy link

Version Used: Visual Studio 17.11.1

Steps to Reproduce:

  1. Create simple incremental generator (it generates source code based on *.txt files as input)

Simple incremental generator (took from docs):

    [Generator]
    public class Generator : IIncrementalGenerator
    {
        public void Initialize(IncrementalGeneratorInitializationContext initContext)
        {
            // define the execution pipeline here via a series of transformations:

            // find all additional files that end with .txt
            IncrementalValuesProvider<AdditionalText> textFiles = initContext.AdditionalTextsProvider.Where(file => file.Path.EndsWith(".txt"));

            // read their contents and save their name
            IncrementalValuesProvider<(string name, string content)> namesAndContents = textFiles.Select((text, cancellationToken) => (name: Path.GetFileNameWithoutExtension(text.Path), content: text.GetText(cancellationToken).ToString()));

            // generate a class that contains their values as const strings
            initContext.RegisterSourceOutput(namesAndContents, (spc, nameAndContent) =>
            {
                File.AppendAllText("E:\\Generator.log", "I am called\n");

                spc.AddSource($"ConstStrings.{nameAndContent.name}", $@"
    public static partial class ConstStrings
    {{
        public const string {nameAndContent.name} = ""{nameAndContent.content}"";
    }}");
            });
        }
    }

Expected Behavior:

Each time when I add or change any *.txt file I should see new file at E:\\Generator.log path.

Actual Behavior:
Incremental generator is invoked only once at build stage. But seems it is not invoked when I add new *.txt file or edit its content.

NOTE:
It worked well in VS 17.10, seems stopped working in 17.11

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Aug 21, 2024
@CyrusNajmabadi
Copy link
Member

This is controlled by:

Image

We also fixed this in 17.12: #74542

Primary issue was that we weren't tracking saves to non-Roslyn files (like your text file). So even saving them wasn't causing generators to rerun.

@CyrusNajmabadi CyrusNajmabadi closed this as not planned Won't fix, can't repro, duplicate, stale Aug 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

2 participants