如何更改“特定版本”添加引用时的默认值?

发布于 2024-09-05 21:58:19 字数 128 浏览 5 评论 0原文

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

有办法改变这个吗?指望手动更改该值很容易出错(并且我最终会破坏构建)。

When I add a reference to my project, I usually want to use Specific Version = FALSE. This is because our automated build will set the version number. I see the default behavior is to be TRUE.

Is there a way to change this? Counting on manually changing that value is error prone (and I end up breaking the build).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半边脸i 2024-09-12 21:58:19

创建 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

Create AddIn Project, and try it:

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
娜些时光,永不杰束 2024-09-12 21:58:19

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

There's not a way to change the default. If you're using TFS you could probably apply a check-in rule, but I am unsure if a check-in rule can be applied to a .csproj or .sln file.

提笔落墨 2024-09-12 21:58:19

我想说你不应该在每次构建时更改程序集版本。您应该使用文件版本来实现此目的。

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

Suzanne Cook 的博文

I would say you should not change the assembly version with each build. You should use the file version for that purpose.

Suzanne Cooke has a nice blog post explaining it in detail, but that summary is that the file version of an assembly need not be the same than the assembly version and for builds you need to up the file version the whole time and not the assembly version.

Suzanne Cook's blog post

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文