简体   繁体   中英

Programmaticaly add file as a link in C# project from inside visual studio add-in using EnvDTE API

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.

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM