private void GenerateSources() { string cswinrtExe = context.GetCsWinRTExe(); string assemblyName = context.GetAssemblyName(); string winmdFile = context.GetWinmdOutputFile(); string outputDir = GetTempFolder(true); string windowsMetadata = context.GetCsWinRTWindowsMetadata(); string winmds = context.GetCsWinRTDependentMetadata(); string arguments = string.Format( "-component -input \"{0}\" -input {1} -include {2} -output \"{3}\" -input {4} -verbose", winmdFile, windowsMetadata, assemblyName, outputDir, winmds); Logger.Log("Running " + cswinrtExe + " " + arguments); var processInfo = new ProcessStartInfo { FileName = cswinrtExe, Arguments = arguments, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, WindowStyle = ProcessWindowStyle.Hidden, CreateNoWindow = true }; try { using var cswinrtProcess = Process.Start(processInfo); Logger.Log(cswinrtProcess.StandardOutput.ReadToEnd()); Logger.Log(cswinrtProcess.StandardError.ReadToEnd()); cswinrtProcess.WaitForExit(); if (cswinrtProcess.ExitCode != 0) { throw new Win32Exception(cswinrtProcess.ExitCode); } foreach (var file in Directory.GetFiles(outputDir, "*.cs", SearchOption.TopDirectoryOnly)) { Logger.Log("Adding " + file); context.AddSource(Path.GetFileNameWithoutExtension(file), SourceText.From(File.ReadAllText(file), Encoding.UTF8)); } } finally { if (!context.GetKeepGeneratedSources()) { Directory.Delete(outputDir, true); } } }