public static NugetInfo GetNugetInfoFromNugetInfoReference([NotNull] XElement xElement, [MaybeNull] string sourceFilePath = null) { if (xElement == null) { throw new ArgumentNullException(nameof(xElement)); } if (!IsNugetInfoReference(xElement)) { throw new InvalidOperationException($"传入的键不含 Nuget 信息,详情:{xElement}"); } var includeValue = xElement.Attribute(IncludeAttribute).Value; var nugetName = _nugetNameRegex.Match(includeValue).Value; var nugetVersion = _nugetVersionRegex.Match(includeValue).Value; if (string.IsNullOrWhiteSpace(sourceFilePath)) { return(new NugetInfo(nugetName, nugetVersion)); } var dllPath = GetDllPath(xElement, Path.GetDirectoryName(sourceFilePath)); var nugetDllInfo = new NugetDllInfo(dllPath, includeValue); return(new NugetInfo(nugetName, nugetVersion, nugetDllInfo)); }
/// <summary> /// 构造一条 Nuget 包信息 /// </summary> /// <param name="name">名称</param> /// <param name="version">版本号</param> /// <param name="nugetDllInfo">Dll 信息</param> public NugetInfo(string name, string version, NugetDllInfo nugetDllInfo) : this(name, version) { NugetDllInfo = nugetDllInfo; }