private static async Task<CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location)) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll"), Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.Azure.dll") }) )); return await compiler.Compile(Microsoft.Rest.CSharp.Compiler.Compilation.OutputKind.DynamicallyLinkedLibrary); }
protected async Task<CompilationResult> Compile(IFileSystem fileSystem) { var compiler = new CSharpCompiler( fileSystem.GetFiles("GeneratedCode", "*.cs", SearchOption.AllDirectories) .Select(each => new KeyValuePair<string, string>(each, fileSystem.ReadFileAsText(each))).ToArray(), ManagedAssets.FrameworkAssemblies.Concat( AppDomain.CurrentDomain.GetAssemblies() .Where(each => !each.IsDynamic && !string.IsNullOrEmpty(each.Location) ) .Select(each => each.Location) .Concat(new[] { Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.dll"), Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.Rest.ClientRuntime.Azure.dll") }) )); var result = await compiler.Compile(OutputKind.DynamicallyLinkedLibrary); // if it failed compiling and we're in an interactive session if (!result.Succeeded && System.Environment.OSVersion.Platform == PlatformID.Win32NT && System.Environment.UserInteractive) { var error = result.Messages.FirstOrDefault(each => each.Severity == DiagnosticSeverity.Error); if (error != null) { // use this to dump the files to disk for examination // open in Favorite Code Editor InspectWithFavoriteCodeEditor(fileSystem.SaveFilesToTemp(GetType().Name), error.Location.GetMappedLineSpan()); } } return result; }