Skip to content

MSBuild process assumes generated file in project root, not at generation site #36

Description

@thygrrr

The Generator generates correct files for me, and places them right by the side of the .csx file.
However, the compile process fails and expects the file in the project root.

I'd rather have the file right beside the .csx file, or in another subdirectory.
image

Activity

  1. thygrrr commented on Nov 14, 2024

    @thygrrr
    Author

    The command line generator does the same, also placing the file at the project root (except the naming is different - Streams.generated.cs)

  2. thygrrr commented on Nov 14, 2024

    @thygrrr
    Author

    If I write the source like this:

     context[$"generated\\Streams.g.cs"].Write($$"""{{source}}""");

    This will create the file in ANOTHER subdirectory (generator/generated/Streams.g.cs), and then the MSBuild task will look for the file in 'P:\fennECS\fennecs\generated\Streams.g.cs' (again 1 directory too high)

  3. thygrrr commented on Nov 14, 2024

    @thygrrr
    Author

    Running this from the Root of the project (with the files cluttering the root), this works according to the documentation.

    However, the build task does not seem to care about dependencies, and runs in full every time the solution is built (instead of tracking which, if any, .csx files were changed). This adds a significant chunk of compilation time that strongly affects test-driven development workflows.

  4. thygrrr commented on Nov 14, 2024

    @thygrrr
    Author
        <PropertyGroup>
            <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
        </PropertyGroup>
        
        <ItemGroup>
            <StreamTemplate Include="generators\Streams.*.csx">
                <OutputFile>generated\%(Filename).g.cs</OutputFile>
            </StreamTemplate>
        </ItemGroup>
    
        <Target Name="GenerateStreamRunners"
                BeforeTargets="CoreCompile"
                Inputs="@(StreamTemplate)"
                Outputs="@(StreamTemplate->'%(OutputFile)')">
            <Exec Command="dotnet-codegencs template run %(StreamTemplate.Identity) -o generated"
                  WorkingDirectory="$(ProjectDir)"/>
        </Target>
    This is my current workaround.
    
  5. added
    bugSomething isn't working
    help wantedExtra attention is needed
    on Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions