【问题标题】:Is there a way to ease the pain of maintaining .NET assembly references?有没有办法减轻维护 .NET 程序集引用的痛苦?
【发布时间】:2009-03-26 18:03:41
【问题描述】:

我目前正在处理一个涉及多个程序集的网络项目,其结构如下:

WebProject
 |
 +--> A (external assembly, Version 1.0.0.0)
 |
 +--> B (external assembly, Version 1.0.0.0)

困难在于,为了跟踪部署的内容,我想在每次构建时更新程序集 A 和 B 的版本号。现在我正在使用[assembly: AssemblyVersion("1.0.*")] 技术来做这件事,但它在 WebProject 项目中造成严重破坏,因为它包含许多 ASP.NET 页面和引用程序集 A 和 B 中的类型的母版页。

除了手动更新这些引用之外,还有更简单的方法吗?

更新:程序集 A 和 B 存在于一个解决方案中,而 WebProject 存在于另一个解决方案中。此外,A 和 B 的名称很重,因为它们被部署到 IIS/SharePoint 服务器。

【问题讨论】:

    标签: .net asp.net reflection assemblies metadata


    【解决方案1】:

    您是否直接引用已编译的程序集?考虑将它们添加到您的解决方案中,并将它们作为项目参考。

    如果操作正确,这也适用于多个应用程序使用的程序集,因为每个“父”解决方案都可以包含引用。当然,这导致了不可避免的挑战,即了解“此更改是否会破坏任何其他应用程序”,这需要大量计划。通过对接口和/或抽象类进行编码并将无法通过重载完成的任何签名更改视为“破坏性更改”,这需要对使用这些程序集的其他应用程序进行回归,从而稍微缓解了这个问题。

    【讨论】:

      【解决方案2】:

      对于同一解决方案中的项目引用,这是自动完成的。

      如果 A 和 B 不在同一个解决方案中,那么您可以将对它们的引用设置为不需要特定版本(查看引用属性) - 但请注意,这仅适用于编译时,因此您仍将当 A 或 B 更新时,需要重新编译 web 项目。

      您可能无法查看程序集绑定重定向。

      【讨论】:

        【解决方案3】:

        在 Cedaron 的构建过程中,我们通过构建脚本将它们复制到 Web 项目的 bin 目录中来维护 Web 项目中的引用,而不是声明引用。

        你不会认为这会奏效,但它确实有效。如果它们在 bin 目录中,则可以使用它们。

        【讨论】:

          【解决方案4】:

          原来我发现了一个博客,描述了一种使用 TortoiseSVN 附带的 subwcrev 工具将 1.0.0.$REV$ 替换为 1.0.0.25 或其他内容的方法。这几乎是我想要的。这很正常。

          【讨论】:

          • 假设我每天提交 10 次。我不知道,但让我们假设。在这成为问题之前,我将有 6,553 天的时间。这给了我 18 年的时间来找出不同的东西。
          【解决方案5】:

          我使用 powershell 脚本来做同样的事情,独立于 SVN 或任何特定版本控制系统的使用。

          # SetVersion.ps1
          #
          # Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in any subdirectory.
          #
          # usage:  
          #  from cmd.exe: 
          #     powershell.exe SetVersion.ps1  2.8.3.0
          # 
          #  from powershell.exe prompt: 
          #     .\SetVersion.ps1  2.8.3.0
          #
          # last saved Time-stamp: <2009-February-11 22:18:04>
          #
          
          
          function Usage
          {
            echo "Usage: ";
            echo "  from cmd.exe: ";
            echo "     powershell.exe SetVersion.ps1  2.8.3.0";
            echo " ";
            echo "  from powershell.exe prompt: ";
            echo "     .\SetVersion.ps1  2.8.3.0";
            echo " ";
          }
          
          
          function Update-SourceVersion
          {
            Param ([string]$Version)
          
            $NewVersion = 'AssemblyVersion("' + $Version + '")';
            $NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';
          
            foreach ($o in $input) 
            {
          
              #### !! do Version control checkout here if necessary 
              Write-output $o.FullName
              $TmpFile = $o.FullName + ".tmp"
          
               get-content $o.FullName | 
                  %{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
                  %{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion }  > $TmpFile
          
               move-item $TmpFile $o.FullName -force
            }
          }
          
          
          function Update-AllAssemblyInfoFiles ( $version )
          {
            foreach ($file in "AssemblyInfo.cs", "AssemblyInfo.vb" ) 
            {
              get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
            }
          }
          
          
          # validate arguments 
          $r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");
          
          if ($r.Success)
          {
            Update-AllAssemblyInfoFiles $args[0];
          }
          else
          {
            echo " ";
            echo "Bad Input!"
            echo " ";
            Usage ;
          }
          

          【讨论】:

            猜你喜欢
            • 2017-01-24
            • 2015-01-20
            • 2017-08-21
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-07-23
            • 1970-01-01
            相关资源
            最近更新 更多