private static async Task Run() { MSBuildLocator.RegisterDefaults(); var srcPath = @"/Users/rogerjohansson/RiderProjects/ConsoleApp4/ConsoleApp4.sln"; var ws = MSBuildWorkspace.Create(); ws.WorkspaceFailed += (sender, args) => { Console.WriteLine("Workspace failed"); }; var output = @"/demooutput"; var sln = await ws.OpenSolutionAsync(srcPath); Console.WriteLine(sln.Version); foreach (var p in sln.Projects) { Console.WriteLine($"Project {p.Name}"); foreach (var d in p.Documents) { var n = d.Name.ToLowerInvariant(); Console.WriteLine($"Document {n}"); if (n.Contains("assemblyinfo") || n.Contains("assemblyattributes") || !n.EndsWith(".cs")) { continue; } var model = await d.GetSemanticModelAsync(); var root = await d.GetSyntaxRootAsync(); var visitor = new KotlinTranspilerVisitor(model); var res = visitor.Run(root); var o = d.FilePath.Replace("democode", "demooutput"); var fileName = Path.ChangeExtension(o, ".kt"); Directory.CreateDirectory(Path.GetDirectoryName(fileName)); var outputFile = Path.Combine(output, fileName); File.WriteAllText(outputFile, res); // return; } } }
private static async Task Run() { var myPath = Assembly.GetExecutingAssembly().Location; var dir = Path.GetDirectoryName(myPath); var srcPath = Path.GetFullPath(Path.Combine(dir, @"..\..\..")); var ws = MSBuildWorkspace.Create(); var output = srcPath + @"\demooutput"; var sln = await ws.OpenSolutionAsync(srcPath + @"\democode\DemoCode.sln"); foreach (var p in sln.Projects) { foreach (var d in p.Documents) { var n = d.Name.ToLowerInvariant(); if (n.Contains("assemblyinfo") || n.Contains("assemblyattributes") || !n.EndsWith(".cs")) { continue; } var model = await d.GetSemanticModelAsync(); var root = await d.GetSyntaxRootAsync(); var visitor = new KotlinTranspilerVisitor(model); var res = visitor.Run(root); var o = d.FilePath.Replace("democode", "demooutput"); var fileName = Path.ChangeExtension(o, ".kt"); Directory.CreateDirectory(Path.GetDirectoryName(fileName)); var outputFile = Path.Combine(output, fileName); File.WriteAllText(outputFile, res); // return; } } }