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,880
  • 4
  • 42
  • 65
cvillalobosm
  • 156
  • 2
  • 12

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
  • 73,278
  • 17
  • 138
  • 182