Ejemplo n.º 1
0
        /// <summary>
        /// 检查文件格式是否正常
        /// </summary>
        /// <returns>检查结果</returns>
        protected override bool CheckFormat()
        {
            if (!base.CheckFormat())
            {
                return(false);
            }

            switch (NugetConfig.GetNugetConfigType(FilePath))
            {
            case NugetConfigType.PackagesConfig:
                _nugetConfigParser = new PackagesConfigParser(Document);
                break;

            case NugetConfigType.CsProj:
                _nugetConfigParser = new CsProjParser(Document, FilePath);
                break;

            case NugetConfigType.Unknown:
                ErrorMessage = $"无法判断 {FilePath} 是哪种类型的 Nuget 配置文件";
                return(false);

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (!_nugetConfigParser.IsGoodFormat())
            {
                ErrorMessage = CreateFormatErrorMessage(_nugetConfigParser.ExceptionMessage);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public void ReadConfig()
        {
            var configPath = TestFile.FullPath("CLI", "TestNuGet.config.xml");
            var cfg        = NugetConfig.Load(configPath);

            cfg.PackagePath.Should().Be("PathToGlobalPackages");
        }
        /// <summary>
        /// 构造一个 Nuget 配置文件修复器
        /// </summary>
        /// <param name="configPath">Nuget 配置文件路径</param>
        public NugetConfigRepairer([NotNull] string configPath,
                                   [NotNull] IEnumerable <NugetFixStrategy> nugetFixStrategies)
        {
            _nugetFixStrategies = nugetFixStrategies ?? throw new ArgumentNullException(nameof(nugetFixStrategies));
            _xDocument          = new XmlReader(configPath).Document;
            _configPath         = configPath;
            switch (NugetConfig.GetNugetConfigType(configPath))
            {
            case NugetConfigType.PackagesConfig:
                _nugetConfigFixHelper = new PackagesConfigFixHelper(_xDocument, _nugetFixStrategies);
                break;

            case NugetConfigType.CsProj:
                _nugetConfigFixHelper = new CsProjFixHelper(_xDocument, configPath, _nugetFixStrategies);
                break;

            case NugetConfigType.Unknown:
                Log = $"无法判断 {configPath} 是哪种类型的 Nuget 配置文件";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }