0

I am Creating XML File for saving the credentials.

  private void CreateCredentialFile()
   {
        string path = @"Assets\CredentialFile.xml";
        XDocument doc = new XDocument(new XElement("ConferenceRooms"));
         XElement newRoom = new XElement("ConferenceRoom",
                                           new XElement("Email",SelectedConfRoom.EmailId),
                                           new XElement("Password", SelectedConfRoom.Password)
                                       );
        doc.Element("ConferenceRooms").Add(newRoom);
        doc.Save(path);
   }

But If I clean the solution means this file still present in my output directory. I want to this file get removed while cleaning the solution. Is there anyway to remove this file while cleaning the solution?

Dinesh balan
  • 495
  • 4
  • 15

2 Answers2

0

Jon Skeet:

Clean solution will remove the build artifacts from the previous build. If there are any other files in the build target directories (bin and obj) they may not be removed, but actual build artifacts are.

Reference: Difference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?

What it actually means is that as long as you're manually creating files into your application the output folder, they will not be removed when using the Clean Solution command, but only those files which generated by the Visual Studio MS-BUILD.

But, you can add the following section to the project in question in order to perform custom cleaning:

<Target Name="AfterClean">
    <Delete Files="$(TargetDir)\*.txt" />
</Target>
Community
  • 1
  • 1
Yair Nevet
  • 12,725
  • 14
  • 66
  • 108
0

There are a few ways to handle this. If your goal is to remove the XML file prior to building the solution, you can use a Pre-build event. Navigate to your project properties > Compile tab > Build Events (button lower right). In the Build Events window, you can add a command or script to do the necessary pre-build cleanup. This is quite flexible and allows you to externally manage resource files that aren't considered as part of the actual project output.

mjw
  • 1,196
  • 1
  • 12
  • 19