0

Anyone knows how can I add a dependency reference programmatically in C#?

The think is I am already generating a new project programmatically, but I need to add some references to that project.

Is it possible to do it programmatically?

Thanks.

iCantSeeSharp
  • 3,895
  • 4
  • 40
  • 64
cvillalobosm
  • 137
  • 1
  • 11

1 Answers1

2

See Scott's answer here: c# Visual Studio ...adding references programmatically

EnvDTE80.DTE2 pEnv = null;
Type myType = Type.GetTypeFromProgID("VisualStudio.DTE.8.0");          
pEnv = (EnvDTE80.DTE2)Activator.CreateInstance(myType, true);

Solution2 pSolution = (Solution2)pEnv.VS.Solution;
Project pProject = pSolution.Projects[0];
pProject.References.Add(string referenceFilePath);
Community
  • 1
  • 1
Samuel Neff
  • 70,536
  • 16
  • 132
  • 177