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

简介: 【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跨平台的相关内容,可以参考:跨平台.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();
            }
        }


目录
打赏
0
0
0
0
20
分享
相关文章
|
10月前
项目打包报错“caniuse-lite is outdated. Please run next command `npm update`”的解决方案
项目打包报错“caniuse-lite is outdated. Please run next command `npm update`”的解决方案
545 1
|
5月前
mcr.microsoft.com/dotnet/core/aspnet:2.1安装libgdiplus
mcr.microsoft.com/dotnet/core/aspnet:2.1安装libgdiplus
45 1
|
9月前
|
Go
The “gopls“ command is not available. Run “go get -v golang.org/x/tools/gopls“ to install.【已解决】
The “gopls“ command is not available. Run “go get -v golang.org/x/tools/gopls“ to install.【已解决】
109 3
go clean命令 完全解析
go clean命令 完全解析
860 0
小匕首-dotnet cli使用tool指令
小匕首-dotnet cli使用tool指令
198 0
小匕首-dotnet cli使用nuget指令
小匕首-dotnet cli使用nuget指令
167 0
ubuntu下go-zero项目安装goctl后报错:command not found
ubuntu下go-zero项目安装goctl后报错:command not found
830 0
ubuntu下go-zero项目安装goctl后报错:command not found
使用dotnet Cli向nuget发布包
长话短说, 今天分享如何在nuget.org创建并发布.NET Standard package。
使用dotnet Cli向nuget发布包
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等