Including files in Visual Studio projects

0

Good evening. I would like to know if it is possible to include a file in a Visual Studio project programmatically at runtime?

    
asked by anonymous 02.10.2018 / 03:49

1 answer

0

Try it this way:

var p = new Microsoft.Build.Evaluation.Project(@"C:\MyFolder\MyProject.csproj");
string strNewItem = @"C:\MyImages\IMG_20180926-WA0017.jpg";

if (p.Items.FirstOrDefault(x => x.EvaluatedInclude == strNewItem) == null) 
{ 
    p.AddItem("_img", strNewItem);
    p.Save(); 
}

Gets the project and then validates if the file you want to include does not already exist, in which case it adds it to the _img folder and writes the project.

User-submitted Ray Carneiro .

Need to reference Microsoft.Build.dll .

    
02.10.2018 / 10:36