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

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

Open
thygrrr opened this issue Nov 14, 2024 · 4 comments

Comments

@thygrrr
Copy link

thygrrr commented Nov 14, 2024

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

@thygrrr
Copy link
Author

thygrrr commented Nov 14, 2024

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

@thygrrr
Copy link
Author

thygrrr commented Nov 14, 2024

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)

@thygrrr
Copy link
Author

thygrrr commented Nov 14, 2024

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.

@thygrrr
Copy link
Author

thygrrr commented Nov 14, 2024

    <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.

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

1 participant