diff --git a/CHANGELOG.md b/CHANGELOG.md index a7f9d5e8..2b0be4aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,8 +57,15 @@ Example: ## [9.0.0.1] - 2024-11-13 +### DotNetCore.Natasha.CSharp.HotExecutor _ v9.0.0.2: +- 基于 Natasha 的热执行,允许程序在运行时更改代码,并输出新的结果. +- 跟随其他扩展库版本号发布. -### DotNetCore.Natasha.CSharp.HotExecutor.Wrapper _ v9.0.0.2: +### DotNetCore.Natasha.CSharp.HotExecutor.SG _ v9.0.0.2: +- 热执行的 SG 扩展库. +- 跟随其他扩展库版本号发布. +- +### DotNetCore.Natasha.CSharp.HotExecutor.Wrapper _ v9.0.0.3: - 热执行 + SG 封装库. - 跟随其他扩展库版本号发布. diff --git a/samples/ExtensionSample/ExtensionSample.csproj b/samples/ExtensionSample/ExtensionSample.csproj index ee1afffa..55375412 100644 --- a/samples/ExtensionSample/ExtensionSample.csproj +++ b/samples/ExtensionSample/ExtensionSample.csproj @@ -14,6 +14,10 @@ + + diff --git a/samples/ExtensionSample/Program.cs b/samples/ExtensionSample/Program.cs index d2eec1e6..85cdec7d 100644 --- a/samples/ExtensionSample/Program.cs +++ b/samples/ExtensionSample/Program.cs @@ -55,6 +55,7 @@ static void Main(string[] args) // } + // Console.WriteLine("父进程应用程序所在的目录: " ); //} //else diff --git a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs index 154466fc..e9e3dfff 100644 --- a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs +++ b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.SG/HotExecutorGenerator.cs @@ -73,7 +73,6 @@ void ISourceGenerator.Execute(GeneratorExecutionContext context) var nameSapce = context.Compilation.GetEntryPoint(cancellationToken: new System.Threading.CancellationToken())!.ContainingNamespace.Name; string proxyMethodContent = $@" -//#if DEBUG using System.IO; using System.Diagnostics; using System.Runtime.CompilerServices; @@ -103,7 +102,6 @@ internal static void PreMain() }} }} -//#endif "; context.AddSource($"NatashaHotExecutorProxy.g.cs", proxyMethodContent); diff --git a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.Wrapper/targets/DotNetCore.Natasha.CSharp.HotExecutor.Wrapper.targets b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.Wrapper/targets/DotNetCore.Natasha.CSharp.HotExecutor.Wrapper.targets index d77ca0cb..fa5c5bcc 100644 --- a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.Wrapper/targets/DotNetCore.Natasha.CSharp.HotExecutor.Wrapper.targets +++ b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor.Wrapper/targets/DotNetCore.Natasha.CSharp.HotExecutor.Wrapper.targets @@ -1,8 +1,8 @@  - - + + \ No newline at end of file diff --git a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs index 59eb0856..51f0967c 100644 --- a/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs +++ b/src/Natasha.CSharp/Extension/HotExecutor/Natasha.CSharp.HotExecutor/HEProxy.cs @@ -97,13 +97,16 @@ private static void DeployCSProjWatcher() } if (needReBuildAgain) { +#if DEBUG ShowMessage("抢占成功,将重新编译!"); +#endif _buildLock.ReleaseLock(); _csprojWatcher!.Notify(); return; } - +#if DEBUG ShowMessage("构建成功,准备启动!"); +#endif if (await _processor.Run()) { #if DEBUG @@ -115,14 +118,18 @@ private static void DeployCSProjWatcher() { _isFaildBuild = true; _buildLock.ReleaseLock(); +#if DEBUG ShowMessage("构建失败!"); +#endif } } else { _isCompiling = false; +#if DEBUG ShowMessage("检测到多次更改触发多次抢占编译,当前将尽可能抢占编译权限!"); +#endif } }); @@ -239,7 +246,9 @@ public static void Run() _cs0104UsingCache[file] = _cs0104TriviaPlugin.ExcludeUsings; //从默认Using缓存中排除 CS0104 root = UsingsHandler.Handle(root, _cs0104UsingCache); +#if DEBUG ShowMessage(root.ToFullString()); +#endif return CSharpSyntaxTree.Create(root, _currentOptions, file, Encoding.UTF8); } if (root != reBuildRoot) @@ -295,7 +304,9 @@ private static async Task HotExecute() var types = CurrentAssembly.GetTypes(); var typeInfo = CurrentAssembly.GetTypeFromShortName(_proxyMethodPlugin.ClassName!); var methods = typeInfo.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static); +#if DEBUG ShowMessage($"执行主入口前导方法...."); +#endif _preCallback?.Invoke(); if (_cancellations.Count > 0) @@ -344,8 +355,9 @@ private static async Task HotExecute() { instance = Activator.CreateInstance(typeInfo); } - +#if DEBUG ShowMessage($"执行主入口回调方法...."); +#endif if (_asyncTriviaPlugin.IsAsync) { Task mainTask; @@ -380,15 +392,17 @@ private static async Task HotExecute() } } - +#if DEBUG ShowMessage($"执行入口回调方法...."); +#endif _endCallback?.Invoke(); +#if DEBUG ShowMessage($"执行系列方法执行完毕."); +#endif } catch (Exception ex) { - ShowMessage($"热编译运行失败...."); if (ex is NatashaException nex) {