3

I'm trying to add a file to a Visual Studio "Solution Items" folder, using a Project Template Wizard. I'm able to create the folder itself, but when I add a file, it doesn't do anything.

My code (executed from ProjectFinishedGenerating) is

    fullPath = @"path_to_existing_file";
    _solutionFolder.AddFromFile(fullPath);

Where _solutionFolder is a Project instance corresponding the the solution folder.

Kate Gregory
  • 18,808
  • 8
  • 56
  • 85
ulu
  • 5,872
  • 4
  • 42
  • 51
  • I created a thread a MSDN, but haven't had a chance to try it. See http://social.msdn.microsoft.com/Forums/da-DK/vsx/thread/1a86e59e-bb9b-41b7-8bde-220f351a3c34 – ulu Apr 20 '12 at 05:56

1 Answers1

2

I hit the same snag. You need to add it to the ProjectItems:

var _solutionFolder = _vsSolution.AddSolutionFolder(folder);
_solutionFolder.ProjectItems.AddFromFile(fullPath);

Note, I haven't tried the above code. I'm adapting it from my code (which runs in an AddIn):

Dim project As EnvDTE.Project = _vsSolution.AddSolutionFolder(folderName)
_folder = CType(project.Object, SolutionFolder)
_folder.Parent.ProjectItems.AddFromFile(file)
Swoogan
  • 5,298
  • 5
  • 35
  • 47