1

I'm doing a GAX project and I have an action that adds all the files from a folder to a new "Solution Items" folder. This serves to insert the files needed at the project root as the Local.testsettings and the like.

My problem is that when I add a file, it opens immediately. For a .txt file or the like, it's not too bad. For .testsettings file, it opens a modal window that blocks all the process.

What can I do to prevent this opening? I can't use a .close on the ProjectItem.Document because the code is not executed after the mySolution.ProjectItems.AddFromFile(file) statement.

If you know of any way to prevent a file from opening on add (whether it is added by hand or by code) I'd like to know.

The full code, as asked, is :

        DTE dte = GetService<DTE>();

        string folderPath = System.IO.Directory.GetCurrentDirectory() + SolutionFolderPath;

        var solution = dte.Solution as Solution2;
        var solutionItems = solution.AddSolutionFolder("Solution Items");

        foreach (var file in Directory.GetFiles(folderPath))
        {
            var item = solutionItems.ProjectItems.AddFromFile(file);                
        }       

Thanks a lot!

  • 1
    How about showing us how you add the files? You don't need to show us all of them; just show us how you would add a single file that then opens. – John Saunders Feb 19 '11 at 00:51
  • I don't think the issue lies with you--this is pretty much standard behavior for Visual Studio. Adda file to a project/solution, and it is opened immediately. I've got a Connect open on being able to control this behavior. –  Mar 08 '11 at 13:50

1 Answers1

0

A bit of a blast from the past here but I came across this question when I was looking to do exactly the same thing recently for a custom VS multi-project wizard I've written. In VS2017, the quick and simple solution was after adding the files (using similar code to the OP), I called this in my wizard implementation's IWizard.RunFinished method:

DTE.Documents.CloseAll(vsSaveChanges.vsSaveChangesNo);

Note that in my wizard code, I store the _DTE object in a member property in IWizard.RunStarted for later use (outside of the RunStarted method). Now when my template wizard has completed, there are no open documents!

Rory Solley
  • 1,435
  • 1
  • 9
  • 6