dotnet-script 开源项目教程

dotnet-script 开源项目教程

dotnet-scriptRun C# scripts from the .NET CLI.项目地址:https://gitcode.com/gh_mirrors/do/dotnet-script

1. 项目的目录结构及介绍

dotnet-script 项目的目录结构如下:

dotnet-script/
├── .github/
├── .vscode/
├── assets/
├── build/
├── docs/
├── samples/
├── src/
│   ├── Dotnet.Script.Core/
│   ├── Dotnet.Script.DependencyModel/
│   ├── Dotnet.Script.DependencyModel.NuGet/
│   ├── Dotnet.Script.DependencyModel.Project/
│   ├── Dotnet.Script.DependencyModel.Runtime/
│   ├── Dotnet.Script.Emitter/
│   ├── Dotnet.Script.Execution/
│   ├── Dotnet.Script.NuGetMetadataResolver/
│   ├── Dotnet.Script.Package/
│   ├── Dotnet.Script.Tests/
│   ├── Dotnet.Script.Tests.EndToEnd/
│   ├── Dotnet.Script.Tests.Integration/
│   ├── Dotnet.Script.Tests.Unit/
│   ├── Dotnet.Script.Tool/
│   ├── Dotnet.Script.Web/
│   ├── Dotnet.Script.Worker/
├── .gitignore
├── .travis.yml
├── build.cake
├── build.ps1
├── build.sh
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── script.cake
├── script.ps1
├── script.sh
├── version.json

主要目录介绍:

  • .github/: 包含 GitHub 相关的配置文件。
  • .vscode/: 包含 Visual Studio Code 的配置文件。
  • assets/: 包含项目所需的资源文件。
  • build/: 包含构建脚本和相关文件。
  • docs/: 包含项目文档。
  • samples/: 包含示例代码。
  • src/: 包含项目的源代码,分为多个子项目,每个子项目负责不同的功能模块。

2. 项目的启动文件介绍

dotnet-script 项目的启动文件位于 src/Dotnet.Script.Tool/Program.cs。这个文件是整个工具的入口点,负责初始化和启动 dotnet-script 工具。

using System;
using System.Threading.Tasks;
using Dotnet.Script.Core;
using Dotnet.Script.DependencyModel.Context;
using Dotnet.Script.DependencyModel.Logging;
using Dotnet.Script.DependencyModel.Runtime;
using Dotnet.Script.Execution;
using Microsoft.Extensions.CommandLineUtils;

namespace Dotnet.Script.Tool
{
    public class Program
    {
        public static async Task<int> Main(string[] args)
        {
            var app = new CommandLineApplication
            {
                Name = "dotnet-script",
                Description = "Executes C# scripts."
            };

            app.HelpOption("-?|-h|--help");

            var file = app.Argument("[script]", "The path to the script file.");
            var debug = app.Option("-d|--debug", "Enable debug mode.", CommandOptionType.NoValue);
            var configuration = app.Option("-c|--configuration", "The configuration to use for the script.", CommandOptionType.SingleValue);
            var noCache = app.Option("--no-cache", "Disable caching of NuGet packages.", CommandOptionType.NoValue);
            var logLevelOption = app.Option("--loglevel", "The log level to use.", CommandOptionType.SingleValue);

            app.OnExecute(async () =>
            {
                var logLevel = LogLevel.Error;
                if (logLevelOption.HasValue())
                {
                    logLevel = (LogLevel)Enum.Parse(typeof(LogLevel), logLevelOption.Value(), true);
                }

                var logger = new ScriptLogger(logLevel);
                var runtimeDependencyResolver = new RuntimeDependencyResolver(logger);
                var scriptExecutor = new ScriptExecutor(logger, runtimeDependencyResolver);

                var scriptContext = new ScriptContext
                {
                    File = file.Value,
                    Debug = debug.HasValue(),
                    Configuration = configuration.Value(),
                    NoCache = noCache.HasValue()
                };

                return await scriptExecutor.Execute(scriptContext);
            });

            return await app.Execute(args);
        }
    }
}

3. 项目的配置文件介绍

dotnet-script

dotnet-scriptRun C# scripts from the .NET CLI.项目地址:https://gitcode.com/gh_mirrors/do/dotnet-script

  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

任涌重

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值