【发布时间】:2013-12-23 18:17:13
【问题描述】:
让我先说我对组件的概念相当陌生。我正在尝试在名为 API 的命名空间中创建一个方法。方法如下所示:
Partial Public Class AppInfo
' This function will return the VersionMajor Element of the Assembly Version
Function VersionMajor() As String
Dim txt As String = Assembly.GetExecutingAssembly.GetName.Version.Major.ToString()
If txt.Length > 0 Then
Return txt
Else
Return String.Empty
End If
End Function
' This function will return the VersionMinor Element of the Assembly Version
Function VersionMinor() As String
Dim txt As String = Assembly.GetExecutingAssembly.GetName.Version.Minor.ToString()
If txt.Length > 0 Then
Return txt
Else
Return String.Empty
End If
End Function
' This function will return the VersionPatch Element of the Assembly Version
Function VersionPatch() As String
Dim txt As String = Assembly.GetExecutingAssembly().GetName().Version.Build.ToString()
If txt.Length > 0 Then
Return txt
Else
Return String.Empty
End If
End Function
' This function will return the entire Version Number of the Assembly Version
Function Version() As String
Dim Func As New AppInfo
Dim txt As String = VersionMajor() + "." + VersionMinor() + "." + VersionPatch()
If txt.Length > 0 Then
Return txt
Else
Return String.Empty
End If
End Function
End Class
我在同一解决方案中有其他项目调用 API 作为附加参考。我想要完成的是说我有一个引用名为 Test 的 API 项目的项目。在测试的主控制器中,我有一个调用 Version 方法的视图数据。像这样:
Function Index() As ActionResult
Dim func As New API.AppInfo
ViewData("1") = func.Version
Return View()
End Function
我希望 viewdata 返回测试程序集的版本号,但这会返回 API 程序集版本。我在这里做错了什么?
【问题讨论】:
标签: vb.net api methods .net-assembly