dotnet / dotnet/sdk

Feature Request: Add ForceRebuild attribute to <Watch> items for non-C# source file changes during hot reload

Open
#49,934 3 comments 3 reactions 0 assignees View on GitHub
Area-Watch
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

_Originally submitted on https://github.com/dotnet/runtime/issues/118052_

### Problem Statement
Currently, the .NET hot reload mechanism does not consistently trigger rebuilds when non-C# source files are modified, even when these files are critical inputs for source generators. This limitation particularly affects projects using source generators that depend on external files (e.g., GraphQL schemas, JSON configurations, protocol buffers) to generate C# code.

### Current Behavior
When using ```dotnet watch``` on a project that includes source-generated content from non-C# files:
- Changes to ```.graphql``` files do not trigger the Strawberry Shake source generator
- The hot reload process ignores these file changes, resulting in outdated generated code
- Developers must manually restart the application to see changes reflected

### Expected Behavior
The hot reload mechanism should:
1. Detect changes to watched non-C# source files
2. Trigger a full rebuild (rude edit) when these files are modified
3. Re-execute relevant source generators to produce updated assemblies
4. Properly cascade rebuilds through dependent projects

### Use Case Example
In a typical GraphQL client setup using Strawberry Shake:
- **Server Project**: ASP.NET Core application
- **GraphQL.Client Project**: Contains ```.graphql``` query/mutation files
- **Source Generator**: Strawberry Shake generates C# client code from ```.graphql``` files

When modifying ```.graphql``` files during development, the source generator should automatically regenerate the client code and trigger a hot reload.

### Proposed Solution
Introduce a ```ForceRebuild``` attribute for `````` items in MSBuild project files:

```xml

```

This attribute would indicate that changes to these files require a full rebuild rather than attempting incremental compilation.

### Additional Requirements
The `````` mechanism should properly propagate through project references. Currently, parent projects must explicitly watch files in referenced projects:

```xml

```

Ideally, if a referenced project defines watched files with ```ForceRebuild="true"```, the parent project should automatically respect these settings without requiring duplicate configuration.

### Technical Considerations
- Initial implementation could treat these as rude edits, forcing application restart
- Future optimizations could explore more granular source generator invocation and assembly diffing
- The solution should be extensible to support other file types beyond GraphQL (e.g., ```.proto```, ```.json```, ```.yaml```)

### Related Issues
- [ChilliCream/graphql-platform#8464](https://github.com/ChilliCream/graphql-platform/issues/8464)

### Impact
This enhancement would significantly improve the developer experience for projects using source generators, reducing friction in the development workflow and ensuring consistency between source files and generated code during hot reload sessions.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.