开发者

ASP.NET - Accessing copied content

I have a class library project which contains some content files configured with the "Copy if newer" copy build action. This results in the files being copied to a folder under ...\bin\ for every project in the solution. In this same solution, I've got a ASP.NET web project (which is MVC, by the way). In the library I have a static constructor load the files into data structures accessible by the web project. Previously I've been including the content as an embedded resource. I now need to be able to replace them without recompiling. I want to access the data in three different contexts:

  1. Unit testing the library assembly
  2. Debugging the web application
  3. Hosting the site in IIS

For unit testing, Environment.CurrentDirectory points to a path containing the copied content. When debugging however, it points to C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE. I've also looked at Assembly.GetExecutingAssembly().Location which points to C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\c44f9da4\9238ccc\assembly\dl3\eb4c23b4\9bd39460_f7d4ca01\. What I need is to the physical location of the webroot \bin folder, but since I'm in a static constructor in the开发者_运维问答 library project, I don't have access to a Request.PhysicalApplicationPath.

Is there some other environment variable or structure where I can always find my "Copy if newer" files?


Assembly.Location does indeed point to the location of the assembly after it has been shadow copied.

However, that MSDN page states:

To get the location before the file has been shadow-copied, use the CodeBase property.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜