码迷,mamicode.com
首页 > Web开发 > 详细

【dotnet跨平台】"dotnet restore"和"dotnet run"都做了些什么?

时间:2017-07-18 18:42:56      阅读:263      评论:0      收藏:0      [点我收藏+]

标签:源代码   ack   task   cas   csdn   post   star   ret   because   

【dotnet跨平台】"dotnet restore"和"dotnet run"都做了些什么?


前言:

关于dotnet跨平台的相关内容。能够參考:跨平台.NET Core--微软开源方向

当中。.net core基础库叫CoreFX:https://github.com/dotnet/corefx,.net core执行时叫CoreCLR:https://github.com/dotnet/coreCLR, asp.net core各组件库:https://github.com/aspnet


在使用跨平台dotnet时,我们最经常使用的就是"dotnet restore"和"dotnet run"。那么"dotnet restore"和"dotnet run"都做了些什么?


先看下dotnet restore


源代码在:https://github.com/dotnet/cli/tree/rel/1.0.0/src/dotnet/commands/dotnet-restore

入口在这里:https://github.com/dotnet/cli/blob/rel/1.0.0/src/dotnet/commands/dotnet-restore/Program.cs

主要是寻找当前文件夹下的项目文件(project.json),然后利用NuGet库还原整个项目的依赖库,然后遍历每一个文件夹,生成项目文件,继续还原该项目文件里的依赖项:

public static int Run(string[] args)
{
DebugHelper.HandleDebugSwitch(ref args);
var app = new CommandLineApplication(false)
{
Name = "dotnet restore",
FullName = ".NET project dependency restorer",
Description = "Restores dependencies listed in project.json"
};
// Parse --quiet, because we have to handle that specially since NuGet3 has a different
// "--verbosity" switch that goes BEFORE the command
var quiet = args.Any(s => s.Equals("--quiet", StringComparison.OrdinalIgnoreCase));
args = args.Where(s => !s.Equals("--quiet", StringComparison.OrdinalIgnoreCase)).ToArray();
app.OnExecute(() =>
{
try
{
var projectRestoreResult = NuGet3.Restore(args, quiet);
var restoreTasks = GetRestoreTasks(args);
foreach (var restoreTask in restoreTasks)
{
var project = ProjectReader.GetProject(restoreTask.ProjectPath);
RestoreTools(project, restoreTask, quiet);
}
return projectRestoreResult;
}
catch (InvalidOperationException e)
{
Console.WriteLine(e.Message);
return -1;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return -2;
}
});
return app.Execute(args);
}



再来看下dotnet run


源代码在:https://github.com/dotnet/cli/tree/rel/1.0.0/src/dotnet/commands/dotnet-run

入口在这里:https://github.com/dotnet/cli/blob/rel/1.0.0/src/dotnet/commands/dotnet-run/Program.cs

主要是參数处理。真正的实如今:https://github.com/dotnet/cli/blob/rel/1.0.0/src/dotnet/commands/dotnet-run/RunCommand.cs, 假设是交互的就直接执行,否则编译然后执行。

----------------------------------------------------------RunCommand.cs----------------------------------------------------------

 public int Start()
        {
            if (IsInteractive())
            {
                return RunInteractive(Project);
            }
            else
            {
                return RunExecutable();
            }
        }


【dotnet跨平台】"dotnet restore"和"dotnet run"都做了些什么?

标签:源代码   ack   task   cas   csdn   post   star   ret   because   

原文地址:http://www.cnblogs.com/jhcelue/p/7201925.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!