Question: I want to change the 'csproj' file of my unity project in order to be able to access a specific library as [this](https://stackoverflow.com/questions/5694/the-imported-project-c-microsoft-csharp-targets-was-not-found) answer sugests.

I am manually editing the file but every time i reload the project, the 'csproj' file returns to it's initial state.

Is this a common issue? Is there a way to avoid this and change the file permanently?

---

EDIT: My goal is to use **CSharpCodeProvider** so if there is another way of doing it without changing the 'csproj' file, i will gladly adopt the approach

Answer: 
Just for completeness:

There is an undocumented feature in Unity which allows you to edit the generated `.csproj` files (programmatically), by using an `AssetPostprocessor`:

Inside any folder under `Assets` named `Editor`, create a class with the following structure:

```
public class CsprojPostprocessor : AssetPostprocessor {
        public static string OnGeneratedCSProject(string path, string content) {
            return PatchCsprojContent(content);
        }
    }

```

where `PathCsprojContent` is a function which returns a patched version of the `.csproj` file with the additions you need.

In case you want to patch only certain `.csproj` files, you can check the path beforehand. For example, if you want to process only the Asset `.csproj` file called `Assembly-CSharp.csproj`, you can add the following check to the start of `OnGeneratedCsProject`:

```
if (!path.EndsWith("Assembly-CSharp.csproj")) {
    return content;
}

```

Reference: <https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/extensibility/customize-project-files-created-by-vstu>
As Suigi suggested, i have created a .dll file with the help of a .Net IDE ([SharpDevelop](http://www.icsharpcode.net/OpenSource/SD/Download/)) and just copied it in the 'Assets' folder of unity.

([How do i create a .dll file with SharpDevelop](http://community.sharpdevelop.net/forums/p/14349/38210.aspx))

Here is the class that i wrote to produce the .dll file:

```
using System;
using System.Collections.Generic;
using System.CodeDom.Compiler;
using System.Diagnostics;
using Microsoft.CSharp;
using System.Reflection;

namespace dllTest {

public class AssemblyGeneration {

    public static Assembly generateAssemblyFromCode(string code, string assemblyFilename) {
        CSharpCodeProvider codeProvider = new CSharpCodeProvider();
        System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters();
        parameters.GenerateExecutable = false;
        parameters.OutputAssembly = assemblyFilename + ".dll";
        CompilerResults results = codeProvider.CompileAssemblyFromSource(parameters, code);

        Assembly assembly = null;
        if (!results.Errors.HasErrors) {
            assembly = results.CompiledAssembly;
            return assembly;
        }
        else {
            return null;
        }
    }
}
}

```

In order to use it in any unity script, just use the namespace 'dllTest'. Then, you can call AssemblyGeneration.generateAssemblyFromCode(...) .