-
Notifications
You must be signed in to change notification settings - Fork 221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Tasks]: 有关【开发时动态之热执行】相关功能的规划与任务细化 (意见搜集与讨论) #301
Comments
|
热执行功能描述
|
不使用 SG 的通用写法
class Program
{
public static void Main(string[] args)
{
//设置当前程序的类型 ,默认为 console
HEProxy.SetProjectKind(HEProjectKind.Console);
//创建热执行的日志输出实例
HEFileLogger logger = new HEFileLogger(debugFilePath);
//设置信息输出方式
HEProxy.ShowMessage = async msg => {
await logger.WriteUtf8FileAsync(msg);
};
//设置 Natasha 需要排除的 程序集
HEProxy.ExcludeGlobalUsing("System.Windows.Controls");
//HE:Debug (当前热编译环境指向为 Debug 编译,可以不写,默认为 Debug)
//编译初始化选项,主要是 Natasha 的初始化操作.
//Once (热编译时使用 Once 剔除该语句,不写也没关系)
HEProxy.SetCompileInitAction(()=>{{
NatashaManagement.RegistDomainCreator<NatashaDomainCreator>();
NatashaManagement.Preheating((asmName, @namespace) =>
!string.IsNullOrWhiteSpace(@namespace) &&
(@namespace.StartsWith(""Microsoft.VisualBasic"") ||
HEProxy.IsExcluded(@namespace)),
true,
true);
}});
//开始执行动态代理.
//Once (热编译时使用 Once 剔除该语句,不写也没关系)
HEProxy.Run();
for (int i = 0; i < args.Length; i++)
{
Console.WriteLine(args[i]);
}
//Once (这句 `//Once` 必须写,防止热编译时被 `Console.ReadKey()` 阻塞)
Console.ReadKey();
}
//方法体中的参数操作对应 Main(string[] args) 中的 args,
//热执行时,Main 将接收到 "参数11",“参数2”,“参数23”
//非必要,可以不写
public static void ProxyMainArguments()
{
ProjectDynamicProxy.AppendArgs("参数11");
ProjectDynamicProxy.AppendArgs("参数2");
ProjectDynamicProxy.AppendArgs("参数23");
}
} SG 清爽版版本写法
class Program
{
//Console
public static void Main(string[] args)
{
//HE:Debug (当前热编译环境指向为 Debug 编译,可以不写,默认为 Debug)
for (int i = 0; i < args.Length; i++)
{
//下面这句 DS 注释在热编译中起到了输出的作用,可以代替 Console.WriteLine(args[i]);
//输出方式可以通过 HEProxy.ShowMessage = async msg => {} 进行设置.
//DS args[i]
Console.WriteLine(args[i]);
}
Console.ReadKey();
}
//Asp.net
public static void Main(string[] args)
{
//不支持 AOT 方案
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCors();
var app = builder.Build();
app.UseStaticFiles();
//.....等等其他设置
//销毁 app 等一系列可销毁的对象。
//方法1 :
HEProxy.SetPreHotExecut(async () => { await app.DisposeAsync(); });
//方法2 :
app.AsyncToHotExecutor();
await app.RunAsync();
Console.ReadKey();
}
//Winform
[STAThread]
static void Main()
{
//Once
ApplicationConfiguration.Initialize();
Application.Run(new Form1());
//Or 两种初始化均支持
Application.Run(new ApplicationContext(new Form1()));
}
}
|
Sequence Diagram(s)sequenceDiagram
participant User
participant HEProxy
participant HETreeMethodRewriter
participant HETreeTriviaRewriter
User->>HEProxy: Start Hot Compilation
activate HEProxy
HEProxy->>HETreeMethodRewriter: Register Method Plugins
activate HETreeMethodRewriter
HETreeMethodRewriter->>HEProxy: Plugins Registered
deactivate HETreeMethodRewriter
HEProxy->>HETreeTriviaRewriter: Register Trivia Plugins
activate HETreeTriviaRewriter
HETreeTriviaRewriter->>HEProxy: Plugins Registered
deactivate HETreeTriviaRewriter
HEProxy->>HEProxy: Rewrite Methods and Comments with Plugins
User->>HEProxy: Complete Hot Compilation
deactivate HEProxy
|
状态机支持在热执行环境中,热执行库本身为高权限操作库,Main 首次执行会将主逻辑交给 [热执行库] 进行[域代理运行],因此后续除非更改依赖库 源码、 csproj 文件触发重建。 举例: //设置
HEProxyState .SetValue(0);
//或
HEProxyState <int>.Value = 0;
//增加计数
HEProxyState <int>.Value+=1;
顶级语句支持
SG 支持
隐式 using 支持
注释命令
兼容特殊语法节点指令
支持桌面应用程序热执行
|
已测试项
|
现存问题
|
VS2022 更新后 SG 功能有BUG,目前不敢推广。 |
📃 计划清单 (Tasklist).
基于 VS C# 项目的热执行功能
The text was updated successfully, but these errors were encountered: