开发者

Prevent new file from opening on add

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!


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜