views:

60

answers:

2

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?

+2  A: 

No this type of functionality is not available. A reload of a project from this dialog is effectively implemented by unloading the project, which includes closing all of it's files and then reloading the project from disk.

There is definitely not an option in Visual Studio you can set to change this behavior and I don't know of any extension that would allow for this.

JaredPar
I worked around this with a macro, ugly workaround, but kind of works
Sam Saffron
+6  A: 

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.

Sam Saffron
Why didn't you tell me about this in our team chat? DON'T YOU LOVE ME?
Jarrod Dixon
@Jarrod, I'm trying to keep all my competitive advantages, I just can't keep up with you otherwise :)
Sam Saffron