简体   繁体   English

EnvDTE - 以静默方式将文件添加到项目中

[英]EnvDTE - add file to project silently

I am using EnvDTE to add projects and files to existing solution.我正在使用 EnvDTE 将项目和文件添加到现有解决方案中。 I do it like that:我这样做:

SolutionFolder folder = GetExistingSolutionFolder(folderTree);
if(folder != null)
    folder.Parent.ProjectItems.AddFromFile(filePath);

Nevermind the GetExistingSolutionFolder.没关系 GetExistingSolutionFolder。 It all works.这一切都有效。 But... When I try to add.docx file to solution, it is indeed added, but it is also opened in MsWord.但是...当我尝试将.docx 文件添加到解决方案时,它确实被添加了,但它也在MsWord 中打开。 And when I add.rc file to solution, it is checked against files that are provided inside rc file.当我将 .rc 文件添加到解决方案时,它会根据 rc 文件中提供的文件进行检查。 If there is no file on the disk, a message is thrown.如果磁盘上没有文件,则会抛出一条消息。

So, my question is - can I somehow add the files silently?所以,我的问题是 - 我可以以某种方式静默添加文件吗? Without automaticaly open docx in MsWord or not checking rc files?没有在 MsWord 中自动打开 docx 或不检查 rc 文件?

According to your description, you want to add.doc file in the project sliently.根据您的描述,您想在项目中悄悄添加.doc文件。

I recommend you to use Microsoft.build.我建议您使用 Microsoft.build。

You can try the following code to solve this problem.您可以尝试以下代码来解决此问题。

    var p = new Microsoft.Build.Evaluation.Project(projectpath);
    p.AddItem("Compile", filepath);
    p.Save();

First, you need to add the Microsoft.build.首先,您需要添加 Microsoft.build。

在此处输入图像描述

Second, projectpath should be like: D:\Test\TestAdditem\ConsoleApp1\ConsoleApp1.csproj .其次,项目路径应该是: D:\Test\TestAdditem\ConsoleApp1\ConsoleApp1.csproj

Third, you can see the following result.第三,可以看到如下结果。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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