【问题标题】:How do I change "Specific Version" default value when adding a reference?添加参考时如何更改“特定版本”默认值?
【发布时间】:2010-06-15 13:05:19
【问题描述】:

当我添加对我的项目的引用时,我通常想使用特定版本 = FALSE。这是因为我们的自动构建会设置版本号。我看到默认行为是 TRUE。

有没有办法改变这种情况?指望手动更改该值很容易出错(我最终会破坏构建)。

【问题讨论】:

    标签: c# .net visual-studio-2010 csproj


    【解决方案1】:

    创建 AddIn 项目,然后尝试一下:

    Imports Extensibility
    Imports EnvDTE
    Imports EnvDTE80
    Imports VSLangProj
    Imports VSLangProj80
    
    Public Class Connect
    
        Implements IDTExtensibility2
    
        Private _app As DTE2
        Private WithEvents _RefEvents As ReferencesEvents
    
        '''<summary>Implements the constructor for the Add-in object. Place your initialization code within this method.</summary>
        Public Sub New()
        End Sub
    
        '''<summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
        '''<param name='application'>Root object of the host application.</param>
        '''<param name='connectMode'>Describes how the Add-in is being loaded.</param>
        '''<param name='addInInst'>Object representing this Add-in.</param>
        '''<remarks></remarks>
        Public Sub OnConnection(ByVal application As Object, ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, ByRef custom As Array) Implements IDTExtensibility2.OnConnection
            _app = CType(application, DTE2)
            _RefEvents = CType(_app.Events.GetObject("VBReferencesEvents"), ReferencesEvents)
        End Sub
    
        '''<summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
        '''<param name='disconnectMode'>Describes how the Add-in is being unloaded.</param>
        '''<param name='custom'>Array of parameters that are host application specific.</param>
        '''<remarks></remarks>
        Public Sub OnDisconnection(ByVal disconnectMode As ext_DisconnectMode, ByRef custom As Array) Implements IDTExtensibility2.OnDisconnection
        End Sub
    
        '''<summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification that the collection of Add-ins has changed.</summary>
        '''<param name='custom'>Array of parameters that are host application specific.</param>
        '''<remarks></remarks>
        Public Sub OnAddInsUpdate(ByRef custom As Array) Implements IDTExtensibility2.OnAddInsUpdate
        End Sub
    
        '''<summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
        '''<param name='custom'>Array of parameters that are host application specific.</param>
        '''<remarks></remarks>
        Public Sub OnStartupComplete(ByRef custom As Array) Implements IDTExtensibility2.OnStartupComplete
        End Sub
    
        '''<summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary>
        '''<param name='custom'>Array of parameters that are host application specific.</param>
        '''<remarks></remarks>
        Public Sub OnBeginShutdown(ByRef custom As Array) Implements IDTExtensibility2.OnBeginShutdown
        End Sub
    
        Private Sub _RefEvents_ReferenceAdded(ByVal pReference As Reference) Handles _RefEvents.ReferenceAdded
            If pReference.Version <> "0.0.0.0" Then
                CType(pReference, Reference3).SpecificVersion = True
            End If
        End Sub
    End Class
    

    【讨论】:

      【解决方案2】:

      没有办法更改默认值。如果您使用的是 TFS,您可能会应用签入规则,但我不确定是否可以将签入规则应用于 .csproj 或 .sln 文件。

      【讨论】:

        【解决方案3】:

        我会说您不应该在每次构建时更改程序集版本。您应该为此目的使用文件版本。

        Suzanne Cooke 有一篇不错的博客文章详细解释了它,但总结是程序集的文件版本不必与程序集版本相同,对于构建,您需要始终升级文件版本,而不是汇编版本。

        Suzanne Cook's blog post

        【讨论】:

          猜你喜欢
          • 2011-08-16
          • 1970-01-01
          • 2018-06-06
          • 1970-01-01
          • 1970-01-01
          • 2017-12-13
          • 1970-01-01
          • 2012-10-04
          • 2017-03-23
          相关资源
          最近更新 更多