Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a setting in VS 2010 that will allow it to recover open files after a project file changes?

Tags:

If I have 10 files open and I amend my csproj file (for example: add a space) visual studio complains:

 The project "XYZ" has been modified outside the environment.   Press Reload to load the updated project from disk. Press Ignore to ignore the external changes. The change will be used the next time you open the project.  

Now, I really want to reload cause there are important changes, but I do not want Visual Studio to close all my open files, instead I would like it to refresh the ones that still exist and close the missing ones.

Is there any way to get that kind of functionality?

like image 661
Sam Saffron Avatar asked Sep 24 '10 01:09

Sam Saffron


People also ask

How do I recover an unsaved project in Visual Studio?

Found my lost project by going to "C:\Users{Username}\AppData\Local", right clicking on the Local folder, clicking on "Restore previous versions," selecting the appropriate version, and clicking the "Open" button.

How do I recover files in Visual Studio?

You can also specify if you want to restore modified files if Visual Studio shuts down unexpectedly. To access this dialog box, go to Tools > Options > Environment > AutoRecover.

Where are my Visual Studio projects saved?

When you create a new project, Visual Studio saves it to its default location, %USERPROFILE%\source\repos. To change this location, go to Tools > Options > Projects and Solutions > Locations. For more information, see Options dialog box: Projects and Solutions > Locations.

What is a solution file in Visual Studio?

A solution is a structure for organizing projects in Visual Studio. The solution maintains the state information for projects in two files: . sln file (text-based, shared) .


2 Answers

Yes, I wrote an extension to fix this problem in VS10 and VS11: http://visualstudiogallery.msdn.microsoft.com/6705affd-ca37-4445-9693-f3d680c92f38

Enjoy.

like image 118
Scott Hanselman Avatar answered Oct 20 '22 20:10

Scott Hanselman


As this functionality is not built it, I wrote the following macro:

Public Sub ReloadProject()     Dim oldFiles As List(Of String)     oldFiles = New List(Of String)      Dim projName = DTE.ActiveDocument.ProjectItem.ContainingProject.Name      For iDoc = DTE.Documents.Count To 1 Step -1         Dim name = (DTE.Documents.Item(iDoc).FullName)         oldFiles.Add(name)         DTE.Documents.Item(iDoc).Close(vsSaveChanges.vsSaveChangesPrompt)     Next      Dim projPath As String = DTE.Solution.Properties.Item("Name").Value.ToString() & "\" & projName      Dim solutionExplorer As Window = DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer)     solutionExplorer.Activate()      Dim solutionHierarchy As UIHierarchy = solutionExplorer.Object     Dim obj As Object = solutionHierarchy.GetItem(projPath)     obj.Select(vsUISelectionType.vsUISelectionTypeSelect)      DTE.ExecuteCommand("Project.UnloadProject")     DTE.ExecuteCommand("Project.ReloadProject")      oldFiles.Reverse()     For Each file In oldFiles         Dim item = DTE.Solution.FindProjectItem(file)         If Not item Is Nothing Then             item.Open()             item.Document.Activate()         End If     Next  End Sub 

When I get the annoying window telling me to reload, I ignore it. And then run this macro after to reload.

like image 41
Sam Saffron Avatar answered Oct 20 '22 21:10

Sam Saffron