/// <summary> /// Detects the best possible C# compiler version and instantiates it. /// </summary> /// <param name="compilerParameters">The compiler parameters to be used. Version-specific options may be set.</param> /// <param name="manifestFilePath">The path of an assembly file to be added to compiled binaries if possible.</param> private static CodeDomProvider GetCSharpCompiler(this CompilerParameters compilerParameters, string manifestFilePath) { if (Environment.Version.Major == 4) { // C# 4.0/5.0 (.NET 4.0/4.5) compilerParameters.CompilerOptions += " /win32manifest:" + manifestFilePath.EscapeArgument(); return(new CSharpCodeProvider()); } else if (File.Exists(Path.Combine(WindowsUtils.GetNetFxDirectory(WindowsUtils.NetFx35), "csc.exe"))) { // C# 3.0 (.NET 3.5) compilerParameters.CompilerOptions += " /win32manifest:" + manifestFilePath.EscapeArgument(); return(NewCSharpCodeProvider(WindowsUtils.NetFx35)); } else { // C# 2.0 (.NET 2.0/3.0) return(new CSharpCodeProvider()); } }
/// <summary> /// Builds a suitable <see cref="Exception"/> for a given <see cref="Win32Exception.NativeErrorCode"/>. /// </summary> private Exception BuildException(int error) { switch (error) { case Win32ErrorFailNoactionReboot: case Win32ErrorFailShutdown: case Win32ErrorFailRestart: string message = new Win32Exception(error).Message + Environment.NewLine + StringUtils.Join(Environment.NewLine, ListAppProblems(out var permissionDenied)); if (permissionDenied) { return(new UnauthorizedAccessException(message)); } else { return(new IOException(message)); } default: return(WindowsUtils.BuildException(error)); } }