从 .Dtsx 文件自动检索版本号
简介:
手动检索包大量 SSIS 文件的版本可能很乏味。本文提供了自动化此过程的各种方法。
在 SSIS 包中使用系统变量:
访问包中的 SSIS 系统变量以检索版本信息:
获取.dtsx 文件的版本:
将 dtsx 文件解析为 XML/文本:
使用正则表达式:
使用 XML 解析器:
从 Sql Server 中存储的 .dtsx 文件中获取信息:
参考以下内容链接查询:
从中提取数据未存储在 Sql Server 中的 .dtsx 文件:
示例代码使用正则表达式:
Public Sub ReadPackagesInfo(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Read the file contents Dim strContent As String = "" Using sr As New IO.StreamReader(strFile) strContent = sr.ReadToEnd sr.Close() End Using ' Use Regex to extract package version and other properties strPackageFormatVersion = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value ' ... (Additional regex patterns for other properties) ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
使用 Xml 解析器的示例代码:
Public Sub ReadPackagesInfoUsingXmlParser(ByVal strDirectory As String) ' Initialize a list to store package information m_lst.Clear() Dim strPackageFormatVersion As String = "" Dim strCreationDate As String = "" ' ... (Additional property variables) For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories) ' Load the file as XML document Dim xml = XDocument.Load(strFile) ' Create a namespace manager Dim ns As XNamespace = "www.microsoft.com/SqlServer/Dts" Dim man As XmlNamespaceManager = New XmlNamespaceManager(New NameTable()) man.AddNamespace("DTS", "www.microsoft.com/SqlServer/Dts") If Not xml.Root Is Nothing AndAlso Not xml.Root.Descendants(ns + "Property").Attributes(ns + "Name") Is Nothing AndAlso xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").Count > 0 Then ' Extract package version and other properties using XPaths strPackageFormatVersion = xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").FirstOrDefault.Parent.Value ' ... (Additional property extraction using XPaths) End If ' Add package information to the list m_lst.Add(New PackageInfo With { .PackageFileName = strFile, .PackageFormatVersion = strPackageFormatVersion, ' ... (Additional properties) }) Next End Sub
以上是如何自动从多个 .dtsx 文件中检索版本号?的详细内容。更多信息请关注PHP中文网其他相关文章!