0
Try doing 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();
}
Get the project and then validate if the file you want to include does not yet exist, in which case you add it to the folder _img
and save the project.
Indication given by the user Ray Carneiro.
Need to reference Microsoft.Build.dll
.
Thank you João Martins
– Gabriel Bastos
Edited response to contain the library needed for the code to run.
– João Martins
Did the answer help you? Did you solve the problem?
– João Martins