0

I am working on a Visual Studio add-in which as part of its functionality has to modify existing C# project by adding (and removing) project items that are links to files outside project's tree.
I do not seem to find a way to insert a link to a file in a project using methods of ProjectItems interface exposed in EnvDTE namespace.
The alternative would be to manually modify project file and insert XML elements but I would prefer to avoid that and instead to use the interfaces provided by visual studio if possible.

1 Answers1

0

I think that is not possible using the automation model (EnvDTE) for C# (or VB.NET), only for C++. According to the MSDN Docs about ProjectItems.AddFromFile Method:

FileName need not contain a full path as long as the file can be found. How a file is found depends on the programming language. In order to use pathless files in Visual Basic and Visual C#, for example, the files must be in the same directory as the project. If they are not, they are copied over. Visual C++ allows linking to files anywhere on the system.

You can try using the VS native services (it's possible even from an add-in). Specifically, try the IVsProject.AddItem method with VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE.

Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
  • I was not aware of VS Shell services. Many thanks for pointing them out! I did try and was able to create a link that way. – Boris Dachev Sep 20 '15 at 20:13