0

I am using EnvDTE to add projects and files to existing solution. I do it like that:

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

Nevermind the 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. And when I add .rc file to solution, it is checked against files that are provided inside rc file. 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?

Adam Jachocki
  • 1,897
  • 1
  • 12
  • 28

1 Answers1

1

According to your description, you want to add .doc file in the project sliently.

I recommend you to use 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.

enter image description here

Second, projectpath should be like: D:\Test\TestAdditem\ConsoleApp1\ConsoleApp1.csproj.

Third, you can see the following result.

enter image description here

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
  • But what if I'm looking at EnvDTE specifically to replace Microsoft.Build, because it can't handle a Version-Tag in the csproj-File – Hobbamok May 19 '22 at 14:40