How to access content in a class library when launched on a website

I have the name of the class library "VirusScanManager", which contains a folder named "Lib". This folder contains the command line file of the command line and supporting files. All of these files have a "Build Action" set to "Content" and "Copy to Output Directory" for "always copy."

Inside the library, I get the folder path using the following line:

string virusCheckFolder 
= Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Lib");

I have a Tests class library with a link to VirusScanManager. When tests are running, the parameter is virusCheckFolderset to

C:\...\Projects\WebSiteMobileAdmin\Tests\bin\Debug\Lib

and it works because the files are copied there.

I also have a BusinessLogicLayer class library with a link to VirusScanManager. When I launch my site is virusCheckFolderset to

C:\...\WebSites\WebSiteMobileAdmin\Lib

this does not work because the files are actually copied to

C:\...\Projects\WebSiteMobileAdmin\BusinessLogic\bin\Debug\Lib

Then I tried to reflect as Beaner suggested:

string pathToDLL = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase.Replace("file:///", ""));
string virusCheckFolder = Path.Combine(pathToDLL, "Lib");

It gives me

C:\...\WebSites\WebSiteMobileAdmin\Bin\Lib

But this folder does not exist. I have a link to BusinessLogicLayer in WebsiteMobileAdmin and a link to VirusScanManager in BusinessLogicLayer. It seems that when I do the assembly, the dll is created in both BusinessLogicLayer \ bin \ debug and SiteMobileAdmin \ bin, but the lib folder is only copied to BusinessLogicLayer \ bin \ debug.

So, is there a way to get the path to an internal library that works for both scenarios?

+3
source share
1 answer

, , , .

string strPath = System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().CodeBase)
+3

Source: https://habr.com/ru/post/1728203/


All Articles