Skip to content

Commit

Permalink
RE
Browse files Browse the repository at this point in the history
  • Loading branch information
NMSAzulX committed Nov 13, 2024
1 parent 85021c5 commit 1df090e
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 9 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 封装库.
- 跟随其他扩展库版本号发布.

Expand Down
4 changes: 4 additions & 0 deletions samples/ExtensionSample/ExtensionSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<Compile Remove="InteroAttribute.cs" />
</ItemGroup>

<!--<ItemGroup>
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor.Wrapper" Version="9.0.0.2" />
</ItemGroup>-->

<!--<ItemGroup>
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor.Wrapper" Version="9.0.0.1" />
</ItemGroup>-->
Expand Down
1 change: 1 addition & 0 deletions samples/ExtensionSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static void Main(string[] args)
// }



// Console.WriteLine("父进程应用程序所在的目录: " );
//}
//else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -103,7 +102,6 @@ internal static void PreMain()
}}
}}
//#endif
";

context.AddSource($"NatashaHotExecutorProxy.g.cs", proxyMethodContent);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<!-- 编辑项目文件,添加指定的 PackageReference 节点 -->
<ItemGroup>
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor.SG" Version="9.0.0.1" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor" Version="9.0.0.1" />
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor.SG" Version="9.0.0.2" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
<PackageReference Include="DotNetCore.Natasha.CSharp.HotExecutor" Version="9.0.0.2" />
<PackageReference Include="DotNetCore.Natasha.CSharp.Compiler.Domain" Version="9.0.0.1" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -115,14 +118,18 @@ private static void DeployCSProjWatcher()
{
_isFaildBuild = true;
_buildLock.ReleaseLock();
#if DEBUG
ShowMessage("构建失败!");
#endif
}
}
else
{
_isCompiling = false;
#if DEBUG
ShowMessage("检测到多次更改触发多次抢占编译,当前将尽可能抢占编译权限!");
#endif
}
});
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -344,8 +355,9 @@ private static async Task HotExecute()
{
instance = Activator.CreateInstance(typeInfo);
}

#if DEBUG
ShowMessage($"执行主入口回调方法....");
#endif
if (_asyncTriviaPlugin.IsAsync)
{
Task mainTask;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 1df090e

Please sign in to comment.