Project-system: Renaming a file does not refactor the class name

Created on 17 Jan 2019  路  21Comments  路  Source: dotnet/project-system

In VS2017, when I renamed a C# file, I was asked to refactor the class name in the code too (provided their name was the same).

In VS2019 the refactoring is not triggered anymore.

Please restore the original behavior

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/416761/renaming-a-file-does-not-refactor-the-class-name.html
VSTS ticketId: 757839_
_These are the original issue comments:_

Juan Jos茅 Mejia [MSFT] on 1/15/2019, 10:21 AM (30 hours ago):

We appreciate you taking the time to report this problem. We are currently prioritizing problems that are impacting a broad set of our customers, so we may not be able to investigate this one immediately. We know this problem is important to you, so we will continue to monitor it.

_These are the original issue solutions:_
(no solutions)

Most helpful comment

This is fixed in 16.3 preview 1

All 21 comments

Still failing in 16.0.1

Solved in 16.0.2!

Thanks a lot

That's weird because I'm running 16.0.2 and my classes are still not being refactored :(

Hi @dfoulk

I agree with you something is wrong. I tested in an netstandard project and worked. I wrote the message.

New tests :
ConsoleClassic project (new one):

  • Program.cs is not refactored after name is changed (maybe a limitation is applied)
  • I added a new class: Class1.cs and no refactoring problems after name is changed to Prova.cs

Wpf project (old one):

  • App.xaml is not refactored after name is changed (maybe a limitation is applied)
  • renamed and refactoring correctly

Not tested in other projects.

My current version is:

Microsoft Visual Studio Community 2019
Version 16.0.2
VisualStudio.16.Release/16.0.2+28803.202

Regards

@jmroyb I was renaming a model ("ObstAircraftStatus.cs" => "AircraftStatus.cs") in a .NET Core MVC project via the Solution Explorer.

This model was in a project that is contained in a Solution Folder. I have noticed Visual Studio plugins that I created are not working right when modifying files housed in Solution Folders.

Perhaps these Solution Folders are causing issues here too?

System Info

Microsoft Visual Studio Professional 2019
Version 16.0.2
VisualStudio.16.Release/16.0.2+28803.202
Microsoft .NET Framework
Version 4.7.03056

Installed Version: Professional

Visual C++ 2019   00435-60000-00000-AA181
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

Application Insights Tools for Visual Studio Package   9.0.20307.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2019   16.0.12311.10635
ASP.NET and Web Tools 2019

ASP.NET Core Blazor Language Services   16.0.19216.03

ASP.NET Web Frameworks and Tools 2019   16.0.12311.10635
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.0.12311.10635
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.3.7000.2
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.0.12311.10635
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.3.7000.2
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.0.0-beta4-19170-01+1deafee3682da88bf07d1c18521a99f47446cee8
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Extensibility Message Bus   1.1.77 (master@24013d5)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

GitFlow.VS.Extension   1.0
Visual Studio extension that integrates GitFlow

JetBrains ReSharper Ultimate 2019.1   Build 191.0.20190429.185145
JetBrains ReSharper Ultimate package for Microsoft Visual Studio. For more information about ReSharper Ultimate, visit http://www.jetbrains.com/resharper. Copyright 漏 2019 JetBrains, Inc.

Microsoft Azure HDInsight Azure Node   2.3.7000.2
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.3.7000.2
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   2.5
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.3.7000.2
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 - v2.9.0.0

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   1.0
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.0.300 (573eda3)
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   5.0.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61903.25110
Microsoft SQL Server Data Tools

SQL Server Reporting Services   15.0.1300.108
Microsoft SQL Server Reporting Services Designers 
Version 15.0.1300.108

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.10306.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.0.0-beta4-19170-01+1deafee3682da88bf07d1c18521a99f47446cee8
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.4 for F# 4.6   16.0.0.0.  Commit Hash: 809f41207b74a1356208f11b8fa3a15233734050.
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.0.0.515 (d16-0@a3502d929)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.17.4.418 (remotes/origin/d16-0@3d086e814)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.1.47 (31f664d)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   9.2.0.5 (HEAD/292d27fa)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: mono/mono/2018-08-rc@5ad371dab1b
    Java.Interop: xamarin/java.interop/d16-0@c987483
    LibZipSharp: grendello/LibZipSharp/master@44de300
    LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
    MXE: xamarin/mxe/xamarin@b9cbb535
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.26.0@325e91a
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@0a7edd6


Xamarin.iOS and Xamarin.Mac SDK   12.8.0.0 (0aa8452)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Hi @dfoulk

Tested in a similar solution schema and FAILED (4 netstandard project and 1 Console Classic). When a model class is renamed in one of 4 netstandard projects, no rename message appears and references in Program.cs are not renamed):

imatge

Regards

I am on 16.0.3 and it does not work ....

This bug was closed as a duplicate of https://github.com/dotnet/project-system/issues/2852. That bug is not yet fixed so this bug is not either. please follow to progress of https://github.com/dotnet/project-system/issues/2852 to know when this will be fixed

The issue is still there in version 16.2.2(VS 2019 Professional).
I am currently being annoyed by it while working on a .Net Core project.

Can you please issue a definitive fix. Or is there a setting for this that isn't enabled by default in VS2019?

This is fixed in 16.3 preview 1

In 16.3.2 I now get the prompt and the rename of the class is successful, however if I immediately try renaming it again I do not get the prompt and the two diverge.
If I try to rename the same file a few seconds after I get the prompt and it fails with message "Renaming the code element myclass failed."

@jmarolf Similarly to @tommymonk, I am not always able to rename files in 16.3. I usually have to wait a few seconds before clicking "Yes" in the "...Would you also like to perform a rename in this project of all references..." prompt, else I receive an error telling me that the reference updates failed. I'd say it fails 50% of the time if I don't wait awhile to hit "Yes". This is annoying because I always want to quickly hit "Enter" to select "Yes" in the prompt immediately after renaming the file.

I think the issue with the current fix is that the "...Would you also like to perform a rename in this project of all references..." prompt displays before the references are able to be updated. A quick fix for this would be to delay the display of the "...Would you also like to perform a rename in this project of all references..." prompt until the IDE can indeed perform the update on the references.

I would, however, argue that delaying the display of this prompt would make this renaming file/class/references process take too long, even compared to older versions of VS.

So yeah, I think this needs to be reopened.

@dfoulk I believe the issue you are having is https://github.com/dotnet/project-system/issues/5358. Can you confirm that it reproduces on 16.4 Preview?

@jmarolf I don't believe that issue is what I'm experiencing. I do see the prompt- but if I respond too quickly (i.e. spamming Enter)- the renaming of references in other files fail.

It may be worth mentioning I'm working in .NET Core and renaming files referenced in other projects (which may have an impact on execution times).

I do not have 16.4 installed, but I will try to reproduce when I can :)

I'm still getting this problem in 16.4 Preview 2. I'm prompted to rename the class after renaming the file, but then nothing happens. It's been this way for a while now (probably all of 16.4 previews).

@heaths are you using a sdk-style project or the old project format?

SDK-style. Thing is, it did work some weeks ago, and quite a while before that. Happens for small (2 projects) and medium (~12 projects) solutions now, but certainly worked before. Maybe 16.3? I'm on the Preview channel for VS2019.

@heaths if it reproduces 100% of the time can you let me try your project? I am not aware of this particular problem in 16.4 Preview. There are other bugs in rename related to undo stacks but this might be new.

Yes, it repros 100% of the time.

VS: VisualStudioPreview/16.4.0-pre.2.0+29411.138
Solution: https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/keyvault/Azure.Security.KeyVault.sln

Thanks! I'll take a look

Was this page helpful?
0 / 5 - 0 ratings