Kodun içinde bulunduğu derlemenin yolunu nasıl bulabilirim?

Geçerli kodun bulunduğu montajın yolunu almanın bir yolu var mı? Çağıran derlemenin yolunu değil, sadece kodu içeren derlemenin yolunu istiyorum.

Temel olarak birim testimin dll'ye göre bulunan bazı xml test dosyalarını okuması gerekiyor. Test dll'inin TestDriven.NET, MbUnit GUI veya başka bir şeyden çalıştırılıp çalıştırılmadığına bakılmaksızın yolun her zaman doğru şekilde çözülmesini istiyorum.

Edit: İnsanlar ne sorduğumu yanlış anlıyor gibi görünüyor.

Test kitaplığım şu konumda bulunur

C:\projects\myapplication\daotests\bin\Debug\daotests.dll

ve bu yolu almak istiyorum:

C:\projects\myapplication\daotests\bin\Debug\

MbUnit Gui'den çalıştırdığımda şimdiye kadarki üç öneri beni başarısızlığa uğratıyor:

  • Environment.CurrentDirectory c:\Program Files\MbUnit* verir

  • System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location C:\Documents and Ayarlar\george\Local Settings\Temp\ ....\DaoTests.dll*

  • System.Reflection.Assembly.GetExecutingAssembly().Location bir öncekiyle aynı sonucu verir.

Bu yardımcı olur mu?

//get the full location of the assembly with DaoTests in it
string fullPath = System.Reflection.Assembly.GetAssembly(typeof(DaoTests)).Location;

//get the folder that's in
string theDirectory = Path.GetDirectoryName( fullPath );
Yorumlar (12)

Montaj shadow copied olmadığı sürece bu işe yaramalıdır:

string path = System.Reflection.Assembly.GetExecutingAssembly().Location
Yorumlar (0)

Bulunduğunuz geçerli dizin.

Environment.CurrentDirectory;  // This is the current directory of your application

Eğer .xml dosyasını build ile dışarı kopyalarsanız, onu bulmanız gerekir.

veya

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetAssembly(typeof(SomeObject));

// The location of the Assembly
assembly.Location;
Yorumlar (3)