讓我先說這個問題,說我對Assemblies的概念相當陌生。我正嘗試在名爲API的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程序集版本。我在這裏做錯了什麼?