dotnet / dotnet/roslyn

Maui Project Automatic Namespace Adjustment Mangles Explcit References to Old Namespace with "Unmerged Changes"

Open
#79,262 0 comments 0 reactions 0 assignees View on GitHub
Area-IDE untriaged
Dominant language
C#
Stars
20.7k
Forks
4.3k
PR merge metrics
PR metrics pending

Description

_This issue has been moved from [a ticket on Developer Community](https://developercommunity.visualstudio.com/t/Maui-Project-Automatic-Namespace-Adjustm/10925598)._

---
[severity:It's more difficult to complete my work]
Visual Studio 17.14.6

When moving a file from one folder to another, Visual Studio gives the option to automatically adjust namespaces to match the new file location. When i use this option in my Maui projects, anywhere in the code base that is explicitly referencing the moved file will break with automatically added "Unmerged changes".

Example:
In a brand new Maui project created via the template, I add two classes, Class1 and Class2. Class2 is placed inside Folder1. Class1 has a property that looks like this.
```
internal class Class1
{
public Folder1.Class2 MyProperty{ get; set; }
}
```

I then move Class2 from Folder1 -> Folder2 by dragging it in the solution explorer. Visual studio asks me if I want to automatically adjust the namespace and I accept.

The result is that class 1 ends up looking like this:
```
internal class Class1
{
<<<<<<< TODO: Unmerged change from project 'MauiApp1 (net9.0-windows10.0.19041.0)', Before:
public MauiApp1.Folder1.Class2 MyProperty { get; set; }
}
=======
public Class2 MyProperty { get; set; }
}
>>>>>>> After
public MauiApp1.Folder2.Class2 MyProperty { get; set; }
}
```

When applied to a large project this problem effectively makes the automatic namespace adjustment tool unusable if there is substantial use of explicit namespaces. Without it, keeping namespaces consistent with folder structure requires a lot of tedious manual work and makes re-organizing my solution much more difficult than it should be.

**Repro Steps**
- Create a new Maui project
- Add a new class to any sub namespace
- Reference the new class anywhere in the code base explicitly specifying the namespace
- Move the new class to a new location and allow the namespace to be automatically adjusted.

**Expected Result**
References to the new class are properly updated to the new explicit namespace of the class, or the explicit reference is dropped and a using statement is added.

**Observed Result**
Merge conflicts referencing one of the Maui targets are created.

---
### Original Comments

#### Feedback Bot on 6/19/2025, 07:08 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

#### Feedback Bot on 7/4/2025, 08:19 AM:

This issue is currently being investigated. Our team will get back to you if either more information is needed, a workaround is available, or the issue is resolved.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.