How do I export an XML file to the content directory?

I’m working on adding a level editor to my game and every time I try to export the file it exports to Project_Name\bin\Debug\netcoreapp3.1\Content instead of Project_Name\Content which causes a problem when I try to publish the app and release it.

These are my save and load functions:

public static void Save<T>(string path, T obj) {
     XmlSerializer xmlSerializer = new XmlSerializer(obj.GetType());
     using (StreamWriter writer = new StreamWriter(path)) {
        xmlSerializer.Serialize(writer, obj);

public static T Load<T>(string path) {
    using (TextReader reader = new StreamReader(path)) {
       XmlSerializer xml = new XmlSerializer(typeof(T));
       return (T)xml.Deserialize(reader);

I’m avoiding using the IntermediateSerializer as it’s caused problems for me with difficulty importing the files and getting errors. This method works for saving and loading, but I just wish I could save directly into the Content folder without having to change anything so it’d all work for a published alpha build.

I’ve tried using Content.RootDirectory, System.AppDomain.CurrentDirectory, and even $"{System.AppDomain.CurrentDomain.BaseDirectory}" but nothing has worked. Is there any way I can just save the file into the main content directory in the solution explorer without hardcoding that exact file address?

If I’m understanding correctly, you want your XML file to appear alongside the Debug build of your game. Assuming your game EXE builds to Project_Name\bin\Debug\netcoreapp3.1, your goal lines up with the standard behavior of that being the root folder. Putting \Content as the path will load the file from \netcoreapp3.1\Content, as MonoGame will search relative to the game EXE.

Meanwhile, Project_Name\Content is only a source folder for prebuilt content like textures and fonts, which all get copied to the bin folder when you build. You won’t gain anything from saving your XML in the source folder as your game would have to look for ..\..\..\Content to use that same path. You could do it, but that’s a lot of unnecessary nested folders when you would probably be better off going one level down into the relative Content folder.