Q:

Cannot compile file from different project C#

I want to compile a project from another using CSharpCodeProvider
The problem is the compiler see the target class in current directory
CompilerParameters parameters = new CompilerParameters
{
  GenerateExecutable = true,
  IncludeDebugInformation = true,
  GenerateInMemory = false,
  TreatWarningsAsErrors = true,
  WarningLevel = 3,
  CompilerOptions = "/optimize",
  OutputAssembly = "Output.exe",
};
CSharpCodeProvider codeProvider = new CSharpCodeProvider();

CompilerResults results = codeProvider.CompileAssemblyFromFile(parameters, new string[] { "../../../targetDirectory/targetClass.cs" });
var warnings = from e in results.Errors.Cast<CompilerError>()
  where e.IsWarning
  select e;

var errors = from e in results.Errors.Cast<CompilerError>()
  where !e.IsWarning
  select e;

foreach (var warning in warnings)
{
  Console.WriteLine(warning);
}
Console.WriteLine("==========");
foreach (var error in errors)
{
  Console.WriteLine(error);
}

The output Error is: error CS1504: Source file
  'c:\Users\User\Documents\Visual Studio
  2017\Projects\CurrentDirectory\bin\Debug\targetClass.cs' could not be
  opened ('The system cannot find the file specified. ')

A:

The path to the file is using / as the path separator. On Windows the path separator is \. Try using this instead:
CompilerResults results = codeProvider.CompileAssemblyFromFile(parameters, new string[] { @"..\..\..\targetDirectory\targetClass.cs" });

