[英]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. 我正在使用Visual Studio加载项,作为其功能的一部分,它必须通过添加(和删除)项目项来修改现有的C#项目,这些项目项是指向项目树外部文件的链接。
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. 我似乎没有找到使用EnvDTE命名空间中公开的ProjectItems接口方法在项目中插入文件链接的方法。
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. 替代方法是手动修改项目文件并插入XML元素,但我希望避免这种情况,并尽可能使用Visual Studio提供的接口。
I think that is not possible using the automation model (EnvDTE) for C# (or VB.NET), only for C++. 我认为对于C#(或VB.NET)使用自动化模型(EnvDTE),仅对于C ++,是不可能的。 According to the MSDN Docs about ProjectItems.AddFromFile Method :
根据有关ProjectItems.AddFromFile方法的MSDN文档 :
FileName need not contain a full path as long as the file can be found. 只要可以找到文件,FileName不必包含完整路径。 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.
例如,为了在Visual Basic和Visual C#中使用无路径文件,这些文件必须与项目位于同一目录中。 If they are not, they are copied over.
如果不是,则将它们复制过来。 Visual C++ allows linking to files anywhere on the system.
Visual C ++允许链接到系统上任何位置的文件。
You can try using the VS native services (it's possible even from an add-in). 您可以尝试使用VS本机服务(甚至可以通过外接程序使用)。 Specifically, try the IVsProject.AddItem method with VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE .
具体来说,尝试IVsProject.AddItem方法与VSADDITEMOPERATION.VSADDITEMOP_LINKTOFILE 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.