diff --git a/CompiledHandlebars.Cli2/CompiledHandlebars.Core.Cli.csproj b/CompiledHandlebars.Cli2/CompiledHandlebars.Core.Cli.csproj index 7de9b2f..19abc10 100644 --- a/CompiledHandlebars.Cli2/CompiledHandlebars.Core.Cli.csproj +++ b/CompiledHandlebars.Cli2/CompiledHandlebars.Core.Cli.csproj @@ -2,26 +2,24 @@ Exe - net7.0 + net10.0 AnyCPU;x64 CompiledHandlebars.Core.Cli.Program default - - - - - - + + + + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - + + diff --git a/CompiledHandlebars.Cli2/Program.cs b/CompiledHandlebars.Cli2/Program.cs index c81d99b..f12cab9 100644 --- a/CompiledHandlebars.Cli2/Program.cs +++ b/CompiledHandlebars.Cli2/Program.cs @@ -10,6 +10,8 @@ using System.Linq; using Buildalyzer.Workspaces; using Buildalyzer; +using Buildalyzer.Environment; +using Microsoft.Extensions.Logging; namespace CompiledHandlebars.Core.Cli { @@ -125,6 +127,16 @@ public static int Main(string[] args) Console.WriteLine(outerEx); return -1; } + + if (_ExitCode == 0) + Console.WriteLine("Compilation successful!"); + else + { + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"Compilation failed"); + Console.ResetColor(); + } + Console.WriteLine($"Exit-Code: {_ExitCode}"); return _ExitCode; } @@ -149,6 +161,9 @@ private static void PrintUnknownExtension(string ext) private static void CompileProject(CompilerOptions options) { Console.WriteLine($"Loading project '{options.ProjectFile}'..."); + //string x = Console.ReadLine(); + Stopwatch sw = new Stopwatch(); + sw.Start(); var properties = new Dictionary() { { "AdditionalFileItemNames", "none" } }; @@ -158,18 +173,66 @@ private static void CompileProject(CompilerOptions options) List handlebarsFiles; if (options.NetCoreProject) { + StringWriter log = new StringWriter(); try { - AnalyzerManager manager = new AnalyzerManager(); + AnalyzerManagerOptions analyzerOptions = new AnalyzerManagerOptions + { + LogWriter = log + }; + AnalyzerManager manager = new AnalyzerManager(analyzerOptions); + IProjectAnalyzer analyzer = manager.GetProject(options.ProjectFile); - workspace = analyzer.GetWorkspace(); + + //workspace = analyzer.GetWorkspace(); + ILogger logger = manager.LoggerFactory?.CreateLogger(); + workspace = new AdhocWorkspace(); + workspace.WorkspaceChanged += (sender, args) => logger?.LogDebug($"Workspace changed: {args.Kind.ToString()}{System.Environment.NewLine}"); + workspace.WorkspaceFailed += (sender, args) => logger?.LogError($"Workspace failed: {args.Diagnostic}{System.Environment.NewLine}"); + IAnalyzerResult ar = analyzer.Build(new EnvironmentOptions() { Restore = true }).FirstOrDefault(); + ar.AddToWorkspace(workspace); + Console.WriteLine($"AR: {ar.References.Length}"); + //foreach (string s in ar.References) + //{ + // if (File.Exists(s)) + // { + // PortableExecutableReference ss = MetadataReference.CreateFromFile(s); + // if (ss != null) + // {// Console.WriteLine($"MeRef: {ss.FilePath}"); + // } + // else + // Console.WriteLine($"*no Ref: {s}"); + // } + // else + // Console.WriteLine($"*not exist: {s}"); + //} + project = workspace.CurrentSolution.Projects.ElementAt(0); - Console.WriteLine("Ok!"); + sw.Stop(); + Console.WriteLine($"Ok! {sw.Elapsed}"); + //Console.WriteLine($"Log: {log}"); + //Console.WriteLine($"Project document count: {project.DocumentIds.Count}"); + //Console.WriteLine($"MetadataReferences count: {project.MetadataReferences.Count}"); + + ////test stiwa + //Document d1 = project.Documents.FirstOrDefault(i => i.Name == "IPageModel.cs"); + //Document d2 = project.Documents.FirstOrDefault(i => i.Name == "AdminController.cs"); + + //Console.WriteLine($"d1: {d1 != null}"); + //Console.WriteLine($"d2: {d2 != null}"); + + //Compilation c1 = project.GetCompilationAsync().GetAwaiter().GetResult(); + //INamedTypeSymbol symbol = c1.GetTypeByMetadataName("StiftungWarentest.Website.Models.Page.IPageModel"); + //Console.WriteLine($"symbol: {symbol != null}"); + + //MetadataReference a = project.MetadataReferences.FirstOrDefault(m => m.Display.Contains("StiftungWarentest.Website.Models.dll")); + //Console.WriteLine($"MetadataReference: {a != null}"); + handlebarsFiles = new DirectoryInfo(Path.GetDirectoryName(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), options.ProjectFile)))).GetFiles("*.hbs", SearchOption.AllDirectories).Where(f => ShouldCompileFile(f.FullName, options)).Select(f => f.FullName).ToList(); } catch (Exception ex) { - Console.WriteLine($"Following errors occured: {Environment.NewLine}{ex}"); + Console.WriteLine($"Following errors occured: {Environment.NewLine}{ex} - {log.ToString()}"); throw; } } @@ -274,7 +337,7 @@ private static void CompileSolution(CompilerOptions options) if (handlebarsFiles.Count > 0) anyHbsFilesFound = true; } - + if (handlebarsFiles.Any()) { workspace = CompileHandlebarsFiles(project, workspace, handlebarsFiles, options); @@ -410,7 +473,9 @@ private static Workspace CompileHandlebarsFiles(Project project, Workspace works { foreach (var err in partialErrors) { - Console.Error.WriteLine(err); + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"*** {err}"); + Console.ResetColor(); } } } @@ -419,7 +484,9 @@ private static Workspace CompileHandlebarsFiles(Project project, Workspace works private static void PrintError(HandlebarsException error) { - Console.Error.WriteLine($"Compilation failed: {error.Message}"); + Console.ForegroundColor = ConsoleColor.Red; + Console.Error.WriteLine($"*** Compilation failed: {error.Message}"); + Console.ResetColor(); } /// @@ -440,8 +507,18 @@ private static Tuple> CompileHandlebars } else { - Console.WriteLine($"Compiling '{name}' ({@namespace})"); - return HbsCompiler.Compile(content, @namespace, name, containingProject); + Tuple> result = HbsCompiler.Compile(content, @namespace, name, containingProject); + bool hasError = !options.DryRun && (result?.Item2?.Any() ?? false); + if (hasError) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine($"*** Compiling '{name}' ({@namespace})"); + Console.ResetColor(); + } + else + Console.WriteLine($"Compiling '{name}' ({@namespace})"); + + return result; } } diff --git a/CompiledHandlebars.Cli2/Properties/PublishProfiles/FolderProfile.pubxml b/CompiledHandlebars.Cli2/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index 22dc206..0000000 --- a/CompiledHandlebars.Cli2/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Debug - x64 - D:\hbc - FileSystem - netcoreapp3.1 - linux-x64 - false - True - - \ No newline at end of file diff --git a/CompiledHandlebars.Cli2/Properties/PublishProfiles/linux.pubxml b/CompiledHandlebars.Cli2/Properties/PublishProfiles/linux.pubxml new file mode 100644 index 0000000..fd6fe38 --- /dev/null +++ b/CompiledHandlebars.Cli2/Properties/PublishProfiles/linux.pubxml @@ -0,0 +1,18 @@ + + + + + Release + x64 + C:\D\hbc\linux + FileSystem + net10.0 + linux-x64 + false + false + + en + + \ No newline at end of file diff --git a/CompiledHandlebars.Cli2/Properties/PublishProfiles/windows.pubxml b/CompiledHandlebars.Cli2/Properties/PublishProfiles/windows.pubxml new file mode 100644 index 0000000..78dbabd --- /dev/null +++ b/CompiledHandlebars.Cli2/Properties/PublishProfiles/windows.pubxml @@ -0,0 +1,19 @@ + + + + + Release + Any CPU + C:\D\hbc\windows + FileSystem + net10.0 + win-x64 + false + false + + true + en + + \ No newline at end of file diff --git a/CompiledHandlebars.Cli2/Properties/launchSettings.json b/CompiledHandlebars.Cli2/Properties/launchSettings.json index 6d1a1c9..f77010f 100644 --- a/CompiledHandlebars.Cli2/Properties/launchSettings.json +++ b/CompiledHandlebars.Cli2/Properties/launchSettings.json @@ -2,7 +2,19 @@ "profiles": { "CompiledHandlebars.Cli2": { "commandName": "Project", - "commandLineArgs": "-c -d -f -eC:\\dev\\sw.git\\StiftungWarentest.Website\\node_modules -eC:\\dev\\sw.git\\StiftungWarentest.Website\\assets C:\\dev\\sw.git\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj" + // "commandLineArgsOld": "-c -d -eC:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\node_modules -eC:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\assets C:\\dev\\Repos\\StiftungWarentest.Web\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj", + + // "commandLineArgs": "-c -d C:\\dev\\Repos\\Stiwa2\\website\\src\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj" + "commandLineArgs": "-c -d C:\\dev\\Repos\\Stiwa3\\mono\\website\\src\\StiftungWarentest.Website\\StiftungWarentest.Website.csproj" + }, + "WSL": { + "commandName": "WSL2", + "distributionName": "", + // "commandLineArgsOld": "CompiledHandlebars.Core.Cli.dll -c -d -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/ViewsRelaunch -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/Views/Module -e/mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/Views/Shared /mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/StiftungWarentest.Website.csproj", + // "commandLineArgsNew": "CompiledHandlebars.Core.Cli.dll -c -d -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/ViewsRelaunch -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/Views/Module -e/mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/Views/Shared /mnt/c/dev/Repos/Stiwa/Web/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj", + //"commandLineArgs": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/Stiwa2/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj", + "commandLineArgs": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/Stiwa3/mono/website/src/StiftungWarentest.Website/StiftungWarentest.Website.csproj" + // "commandLineArgsAllOld": "CompiledHandlebars.Core.Cli.dll -c -d /mnt/c/dev/Repos/StiftungWarentest.Web/StiftungWarentest.Website/StiftungWarentest.Website.csproj" } } } \ No newline at end of file diff --git a/CompiledHandlebars.sln b/CompiledHandlebars.sln index 43e3b8c..8ed7147 100644 --- a/CompiledHandlebars.sln +++ b/CompiledHandlebars.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30611.23 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33213.308 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompiledHandlebars.Compiler", "Compiler\CompiledHandlebars.Compiler.csproj", "{55E767E0-44F0-4297-9A00-7211B424BE03}" EndProject @@ -19,14 +19,14 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.ActiveCfg = Debug|x64 + {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|Any CPU.Build.0 = Debug|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x64.ActiveCfg = Debug|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x64.Build.0 = Debug|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x86.ActiveCfg = Debug|Any CPU {55E767E0-44F0-4297-9A00-7211B424BE03}.Debug|x86.Build.0 = Debug|Any CPU - {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.ActiveCfg = Release|Any CPU - {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.Build.0 = Release|Any CPU + {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.ActiveCfg = Release|x64 + {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|Any CPU.Build.0 = Release|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x64.ActiveCfg = Release|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x64.Build.0 = Release|x64 {55E767E0-44F0-4297-9A00-7211B424BE03}.Release|x86.ActiveCfg = Release|Any CPU @@ -39,8 +39,8 @@ Global {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Debug|x86.Build.0 = Debug|Any CPU {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|Any CPU.ActiveCfg = Release|Any CPU {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|Any CPU.Build.0 = Release|Any CPU - {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.ActiveCfg = Release|Any CPU - {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.Build.0 = Release|Any CPU + {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.ActiveCfg = Release|x64 + {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x64.Build.0 = Release|x64 {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x86.ActiveCfg = Release|Any CPU {A3B28E61-F74A-4156-BD99-0FD46E475EDF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection diff --git a/Compiler/CompiledHandlebars.Compiler.csproj b/Compiler/CompiledHandlebars.Compiler.csproj index 5321713..c8a3f8d 100644 --- a/Compiler/CompiledHandlebars.Compiler.csproj +++ b/Compiler/CompiledHandlebars.Compiler.csproj @@ -24,17 +24,23 @@ true true + + portable + + + portable + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - - + + diff --git a/Compiler/Introspection/RoslynIntrospector.cs b/Compiler/Introspection/RoslynIntrospector.cs index 6f975fe..f39538c 100644 --- a/Compiler/Introspection/RoslynIntrospector.cs +++ b/Compiler/Introspection/RoslynIntrospector.cs @@ -68,7 +68,7 @@ private Compilation GetCompilationForProject(Project proj) Compilation comp; if (proj.TryGetCompilation(out comp)) return comp; - else return proj.GetCompilationAsync().Result; + else return proj.GetCompilationAsync().GetAwaiter().GetResult(); } public INamedTypeSymbol GetTypeSymbol(string fullTypeName) diff --git a/Compiler/NamespaceUtility.cs b/Compiler/NamespaceUtility.cs index 3dc469c..57d1076 100644 --- a/Compiler/NamespaceUtility.cs +++ b/Compiler/NamespaceUtility.cs @@ -2,29 +2,25 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using System.Text; using System.Threading.Tasks; namespace CompiledHandlebars.Compiler { - public static class NamespaceUtility - { - - public static bool IsPartOf(string fullNamespace, string partNamespace) - { - var partParts = partNamespace.Split('.').Reverse().ToList(); - var fullParts = fullNamespace.Split('.').Reverse().ToList(); - Debug.Assert(partParts.Count <= fullParts.Count, "PartNamespace is longer than FullNamespace"); - if (partParts.Count > fullParts.Count) - return false; - for (int i = 0; i < partParts.Count; i++) - { - if (!partParts[i].Equals(fullParts[i])) - return false; - } - return true; - } - - - } + public static class NamespaceUtility + { + public static bool IsPartOf(string fullNamespace, string partNamespace) + { + List partParts = partNamespace.Split('.').AsEnumerable().Reverse().ToList(); + List fullParts = fullNamespace.Split('.').AsEnumerable().Reverse().ToList(); + Debug.Assert(partParts.Count <= fullParts.Count, "PartNamespace is longer than FullNamespace"); + if (partParts.Count > fullParts.Count) + return false; + for (int i = 0; i < partParts.Count; i++) + { + if (!partParts[i].Equals(fullParts[i])) + return false; + } + return true; + } + } }