0

I generated a bunch of file when ever a customer creates a new workspace and i want to add them to the existing project file what is the best way to that?

Criteria: It needs to work in visual studio and it needs to work in standalone build

// get the project file ...
var projectfile = Directory.GetFiles(Requested.Workspace.AppRoot, "*.csproj", SearchOption.AllDirectories).Single();
var project = new Project(projectfile);

// add generated items ...
foreach (var item in Requested.Manifest.Items)
{
   project.Items.Add(new ProjectItem(item.Info.FullName,"??"));
}

if (!project.Build())
{
   Console.ReadLine();
}

Help anyone?

wendellmva
  • 1,896
  • 1
  • 26
  • 33
  • You can use `EnvDTE.dll`. More information at http://stackoverflow.com/questions/18020062/how-to-add-an-existing-item-to-a-project-programmatically – Mohammad Nadeem Jun 18 '14 at 10:44
  • I generate the files independent of visual studio so I don't have EnvDTE available. – wendellmva Jun 18 '14 at 15:36
  • Maybe my answer here can help you : http://stackoverflow.com/questions/13867117/how-to-add-a-linked-file-to-a-csproj-file-with-msbuild-3-5-framework – granadaCoder Jun 18 '14 at 17:46
  • Yes that would have worked if it has not been marked as obselete and has not replacement in the new build engine – wendellmva Jun 20 '14 at 13:06

1 Answers1

0

You may create a single .cs file and add all the fills content as a method wise into them, and call the specific function according to workspace.

If(workspace 1)
{
// call file1Method()
}

same for other

jiten
  • 5,128
  • 4
  • 44
  • 73