2014-09-25 67 views
1

我有一個ASP.NET應用程序和類庫項目的解決方案。 ASP.NET應用程序正在使用類庫項目。如何在.NET中獲取父項目的程序集名稱?

我想檢查類庫中的ASP.NET應用程序的程序集名稱。

其實我有一個單獨的模型項目的MVC應用程序。 MVC應用程序使用Model項目。我在另一個項目中創建了一個RemoteWithServerSideAttribute並在模型中使用它。在RemoteWithServerSideAttribute類中,我需要控制器組件信息來調用一個方法。如果我使用Assembly.GetCallingAssembly,我得到System.ComponentModel.DataAnnotations組件信息,因爲RemoteWithServerSideAttributeSystem.ComponentModel.DataAnnotations內部的RemoteAttribute繼承。

我想要的是獲取MVC項目的程序集信息。

回答

1

不確定這是否是您要查找的內容,但您可以使用System.Reflection獲取執行裝配信息或輸入裝配信息。

因此,如果您從Web應用程序調用ClassLibrary中的方法,那麼;

System.Reflection.Asembly.GetExecutingAssembly().GetName().Name會給你的類庫

System.Reflection.Assembly.GetCallingAssembly().GetName().Name名字會給你的Web應用程序的名稱。

+0

感謝您的重播。沒關係。請檢查上面的評論,我已經解釋了我想要的東西...... – 2014-09-25 10:01:13

1

看看Assembly.GetCallingAssemblyhere

從中你可以得到它的例如FullNameGetName()

+0

鏈接是波蘭語。如果你可以發佈英文鏈接會更好。 – Krumia 2014-09-25 09:29:28

+0

啊,對不起。定影。 – 2014-09-25 09:30:31

+0

其實我有一個單獨的模型項目的MVC應用程序。 MVC應用程序使用Model項目。我在另一個項目中創建了一個RemoteWithServerSideAttribute,並在模型中使用它。在RemoteWithServerSideAttribute類中,我需要控制器組件信息來調用一個方法。如果我使用Assembly.GetCallingAssembly,則獲取System.ComponentModel.DataAnnotations程序集信息,因爲RemoteWithServerSideAttribute是從System.ComponentModel.DataAnnotations內的RemoteAttribute繼承的。我想獲得MVC項目的組裝信息? – 2014-09-25 09:50:50

相關問題