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?
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.
Second, projectpath should be like: D:\Test\TestAdditem\ConsoleApp1\ConsoleApp1.csproj
.
Third, you can see the following result.
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.