dotnet / dotnet/msbuild

[Bug]: ProjectRootElement.Reload sets ProjectRootElement.HasUnsavedChanges to true

Open
#8,537 0 comments 0 reactions 0 assignees View on GitHub
backlog bug Priority:2 triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

### Issue Description

In my application I host the MSBuild OM and occasionally have to reload from disk. I also save to disk.

I found that `ProjectRootElement.Reload()` sets the `ProjectRootElement.HasUnsavedChanges` property to true as a side effect of the way the xml tree is rebuilt within the PRE object.
This has the unfortunate effect of making my project try to save the xml, even though it hasn't really changed since being read from disk.
And since the reload was for a PRE at a protected location, the PRE.Save method throws. All for a PRE that had never changed.

Can you please clear the `HasUnsavedChanges` property at the end of a `Reload`?

### Steps to Reproduce

Described above.

### Expected Behavior

Reset the `HasUnsavedChanges` property to `false` at the end of a `Reload`.

### Actual Behavior

`HasUnsavedChanges` is `true` after `Reload`

### Analysis

_No response_

### Versions & Configurations

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Locate the ProjectRootElement.Reload entry point and inspect how the XML tree is rebuilt and how HasUnsavedChanges is updated. Add or update coverage for reloading a project from disk; done means Reload leaves HasUnsavedChanges false when no project changes were made.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.