【问题标题】:Automate Version number Retrieval from .Dtsx files从 .Dtsx 文件中自动检索版本号
【发布时间】:2017-09-21 08:18:55
【问题描述】:

有没有办法或查询可以找到 SSIS 包(*.dtsx 文件)的版本号?

我的 Team Foundation Server 中有我想知道的 *.dtsx 文件。

手动的方法是鼠标右键点击包然后点击Compare查看VersionBuild但是有成千上万的包所以手动做真的不可能

注意:这个过程应该是自动化的,而不是手动的

【问题讨论】:

标签: sql sql-server ssis etl ssis-2012


【解决方案1】:

在 dtsx 包中获取值

  • 如果您尝试读取此包中的包版本,您可以访问其中一个 SSIS system variables

    Variable        Type    Description
    -------------------------------------------
    VersionBuild    Int32   The package version.
    VersionComment  String  Comments about the package version.
    VersionGUID     String  The unique identifier of the version.
    VersionMajor    Int32   The major version of the package.
    VersionMinor    Int32   The minor version of the package.
    
  • 如果您正在寻找Package SQL Server版本,您可以在dtsx文件中找到它,如果您以文本(或xml)形式打开它并搜索PackageFormatVersion属性,详细信息在以下链接中提供:

从存储在 Sql server 中的 .dtsx 文件中获取值

您可以点击以下链接:

它包含实现此问题的查询

从未存储在 Sql server 中的 .dtsx 文件中获取值

要自动读取PackageFormatVersion,您可以使用XMLParserRegex 以编程方式读取它。我在 Vb.net 中编写了一个代码,该代码使用 Regex 并循环遍历目录中的 .dtsx 文件并获取 dtsx 文件头中的 PackageFormatVersion 属性和其他属性:

  • 包文件名
  • PackageFormatVersion
  • 创建日期
  • 创作名称
  • 创建者计算机名
  • 创作者姓名
  • DTSID
  • 可执行类型
  • LastModifiedProductVersion
  • 区域设置 ID
  • 对象名称
  • 包类型
  • 版本构建
  • 版本GUID

首先我创建了一个名为 PackageInfo 的类,其中包含上面列出的属性

Public Class PackageInfo

    Public Property PackageFileName As String
    Public Property PackageFormatVersion As String
    Public Property CreationDate As String
    Public Property CreationName As String
    Public Property CreatorComputerName As String
    Public Property CreatorName As String
    Public Property DTSID As String
    Public Property ExecutableType As String
    Public Property LastModifiedProductVersion As String
    Public Property LocaleID As String
    Public Property ObjectName As String
    Public Property PackageType As String
    Public Property VersionBuild As String
    Public Property VersionGUID As String


End Class

使用正则表达式

Private Sub ReadPackagesInfo(ByVal strDirectory As String)


        m_lst.Clear()

        For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories)


            Dim strContent As String = ""

            Using sr As New IO.StreamReader(strFile)

                strContent = sr.ReadToEnd
                sr.Close()

            End Using


            Dim strPackageFormatVersion As String = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value
            Dim strCreationDate As String = Regex.Match(strContent, "(?<=DTS:CreationDate="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strCreationName As String = Regex.Match(strContent, "(?<=DTS:CreationName="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strCreatorComputerName As String = Regex.Match(strContent, "(?<=DTS:CreatorComputerName="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strCreatorName As String = Regex.Match(strContent, "(?<=DTS:CreatorName="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strDTSID As String = Regex.Match(strContent, "(?<=DTS:DTSID="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strExecutableType As String = Regex.Match(strContent, "(?<=DTS:ExecutableType="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strLastModifiedProductVersion As String = Regex.Match(strContent, "(?<=DTS:LastModifiedProductVersion="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strLocaleID As String = Regex.Match(strContent, "(?<=DTS:LocaleID="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strObjectName As String = Regex.Match(strContent, "(?<=DTS:ObjectName="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strPackageType As String = Regex.Match(strContent, "(?<=DTS:PackageType="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strVersionBuild As String = Regex.Match(strContent, "(?<=DTS:VersionBuild="")(.*?)(?="")", RegexOptions.Singleline).Value
            Dim strVersionGUID As String = Regex.Match(strContent, "(?<=DTS:VersionGUID="")(.*?)(?="")", RegexOptions.Singleline).Value



            m_lst.Add(New PackageInfo With {.PackageFileName = strFile,
                      .PackageFormatVersion = strPackageFormatVersion,
                      .CreationDate = strCreationDate,
                      .CreationName = strCreationName,
                      .CreatorComputerName = strCreatorComputerName,
                      .CreatorName = strCreatorName,
                      .DTSID = strDTSID,
                      .ExecutableType = strExecutableType,
                      .LastModifiedProductVersion = strLastModifiedProductVersion,
                      .LocaleID = strLocaleID,
                      .ObjectName = strObjectName,
                      .PackageType = strPackageType,
                      .VersionBuild = strVersionBuild,
                     .VersionGUID = strVersionGUID})


        Next



End Sub

以下代码行是从文件中读取PackageFormatVersion属性的代码

Dim strA As String = Regex.Match(strContent, "(?<=""PackageFormatVersion"">)(.*)(?=</DTS:Property>)", RegexOptions.Singleline).Value

使用 Xml 解析器

    Private Sub ReadPackagesInfoUsingXmlParser(ByVal strDirectory As String)

        m_lst.Clear()

        For Each strFile As String In IO.Directory.GetFiles(strDirectory, "*.dtsx", IO.SearchOption.AllDirectories)

            Dim strPackageFormatVersion As String = ""
            Dim strCreationDate As String = ""
            Dim strCreationName As String = ""
            Dim strCreatorComputerName As String = ""
            Dim strCreatorName As String = ""
            Dim strDTSID As String = ""
            Dim strExecutableType As String = ""
            Dim strLastModifiedProductVersion As String = ""
            Dim strLocaleID As String = ""
            Dim strObjectName As String = ""
            Dim strPackageType As String = ""
            Dim strVersionBuild As String = ""
            Dim strVersionGUID As String = ""


            Dim xml = XDocument.Load(strFile)

            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

                strPackageFormatVersion = xml.Root.Descendants(ns + "Property").Attributes(ns + "Name").Where(Function(x) x.Value = "PackageFormatVersion").FirstOrDefault.Parent.Value

                strCreationDate = If(xml.Root.Attributes(ns + "CreationDate").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreationDate").FirstOrDefault.Value)
                strCreationName = If(xml.Root.Attributes(ns + "CreationName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreationName").FirstOrDefault.Value)
                strCreatorComputerName = If(xml.Root.Attributes(ns + "CreatorComputerName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreatorComputerName").FirstOrDefault.Value)
                strCreatorName = If(xml.Root.Attributes(ns + "CreatorName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "CreatorName").FirstOrDefault.Value)
                strDTSID = If(xml.Root.Attributes(ns + "DTSID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "DTSID").FirstOrDefault.Value)
                strExecutableType = If(xml.Root.Attributes(ns + "ExecutableType").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "ExecutableType").FirstOrDefault.Value)
                strLastModifiedProductVersion = If(xml.Root.Attributes(ns + "LastModifiedProductVersion").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "LastModifiedProductVersion").FirstOrDefault.Value)
                strLocaleID = If(xml.Root.Attributes(ns + "LocaleID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "LocaleID").FirstOrDefault.Value)
                strObjectName = If(xml.Root.Attributes(ns + "ObjectName").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "ObjectName").FirstOrDefault.Value)
                strPackageType = If(xml.Root.Attributes(ns + "PackageType").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "PackageType").FirstOrDefault.Value)
                strVersionBuild = If(xml.Root.Attributes(ns + "VersionBuild").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "VersionBuild").FirstOrDefault.Value)
                strVersionGUID = If(xml.Root.Attributes(ns + "VersionGUID").FirstOrDefault Is Nothing, "", xml.Root.Attributes(ns + "VersionGUID").FirstOrDefault.Value)
            End If



            m_lst.Add(New PackageInfo With {.PackageFileName = strFile,
                      .PackageFormatVersion = strPackageFormatVersion,
                      .CreationDate = strCreationDate,
                      .CreationName = strCreationName,
                      .CreatorComputerName = strCreatorComputerName,
                      .CreatorName = strCreatorName,
                      .DTSID = strDTSID,
                      .ExecutableType = strExecutableType,
                      .LastModifiedProductVersion = strLastModifiedProductVersion,
                      .LocaleID = strLocaleID,
                      .ObjectName = strObjectName,
                      .PackageType = strPackageType,
                      .VersionBuild = strVersionBuild,
                     .VersionGUID = strVersionGUID})

        Next

    End Sub

演示应用

我创建了一个演示应用程序来实现这个过程,您可以从以下链接下载它:

我还为这个演示应用创建了一个新的Git-repository

应用截图

使用 TSQL 从 .dtsx 文件中获取值

您可以在 DBA.StackExchange 阅读我的回答:

PackageFormatVersion 表

这是PackageFormatVersion 表值

SQL Version Build # PackageFormatVersion    Visual Studio Version
2005        9       2                       2005
2008        10      3                       2008
2008 R2     10.5    3                       2008
2012        11      6                       2010 or BI 2012
2014        12      8                       2012 CTP2 or 2013
2016        13      8                       2015

【讨论】:

  • 感谢哈迪的解决方案,我从未在 Vb 中工作过,但我可以尝试您的解决方案。另外,只是为了补充一点,我的所有包都在服务器中而不是在本地,我通过 Visual Studio 访问它们。我只是想知道如何使用 vb 代码从服务器获取所需的信息。
  • 几个小时,我将提供一个演示应用程序链接
  • 我提供的代码是一个将目录作为参数的函数。循环遍历 dtsx 文件并将它们的版本放入列表中。
  • @saurabhsharma 文件在 tfs 中被映射到本地路径,因此更改在本地进行,直到它们被签入。所以在 Visual Studio 的团队资源管理器中右键单击一个包并单击 Open containing folder
  • 感谢您的详细解决方案和所有努力。
【解决方案2】:

如果您使用项目部署解决方案(如果您的服务器中有 SSISDB),则可以使用此查询:

SELECT 
   [name],
   [package_format_version]
FROM [SSISDB].[catalog].[packages];

注意:必须安装集成服务

【讨论】:

  • 不知道为什么我得到了负分?!?但我仍然认为您应该将所有包部署到 SSIS,然后运行上述查询。
  • 我也给了你一票。如果您已将其保存在 SSISDB 中,则非常简单。我越用 SSISDB 越喜欢它。
  • @JacobH SSISDB 非常好,但问题是关于自动化这个过程?我不认为这个查询是 OP 要求的
  • @JacobH 如果您阅读了 OP cmets `我的 TFS 中有我想知道的 *.dtsx 文件。`,他不是在谈论存储在 sql server 中的 dtsx
  • @lahmbajin 将您的项目临时部署到 SQL Server 并运行此查询以查找您拥有的所有包的版本。
【解决方案3】:

.ispac 文件实际上是 zip 文件,每个 .dtsx 都是 XML 文件,其中包含所有必需的信息。另外为了回答朋友发来的问题,XML 本身包含了你想要的所有信息。

希望对你有帮助:)

【讨论】:

  • OP 说The process should be automated, not manual.,所以我们正在寻找一种方法来自动从 xml 读取这些值。看看哈迪的答案,他的方法是正确的,但我正在寻找最佳方法(如果存在)
  • .ispac 是什么?和这个问题有关系吗?
  • .ispac是SSIS包@lahmbajin的部署文件
  • @YasharAliabasi 赞成你的回答。因为这是我们必须开始的地方。看看我的答案,您可以将其视为答案的下一步。祝你好运
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-02
  • 1970-01-01
  • 2021-12-17
相关资源
最近更新 更多