ASP.NET web application project: how to copy a referenced DLL's dependencies to the 'Temporary ASP.NET Files' folder?

混江龙づ霸主 提交于 2019-12-25 02:28:30

问题


I have a web application project WAP that references class library CL. CL needs some xml configuration files in order to work properly.

In WAP's csproj, I add a PostBuildEvent to copy the necessary XML files to the TargetDir. When I build, the folder structure is good; the bin folder contains CL and the xml files.

When I run the webservice, CL throws an error because it can't find the xml files:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\accountreplication\284ca636\19f84c15\assembly\dl3\bf68503c\34888845_bd69cb01\XmlTemplates\Clusters.xml'.

From what I've read, ASP.NET will compile on the fly my files and put them in that 'Temporary ASP.NET' folder. So it seems like my problem is that the xml files from the /bin/ folder are not copied in that temp folder.

Any idea on what I should do to get around this? Either to copy the xml files in the temp folder, or to actually serve the files from the /bin/ directory directly (not sure if this is possible). Ideally, I don't want to add an environment variable to the /bin/ directory.

Thanks!


回答1:


Try adding the XML file as an embeded resouce, if you got properties on the XML file within visual studio, there will be an option to change it.

Regards

Iain




回答2:


Not 100% sure on this, but if you go to the properties window of the xml file that's in your solution, you should be able to set the Copy to Output Directory = Copy Always or Copy if Newer. This should instruct it to copy it to where it's needed.




回答3:


We had a similar problem and ended up adding an appSettings key/value to web.config that our DLL use to find the required files. Files were copied there manually.

<configuration>
  ...
  <appSettings>
    <add key="sExeFolder" value="C:\Project\Support_Files"/>
  </appSettings>
  ...
</configuration>


来源:https://stackoverflow.com/questions/3918305/asp-net-web-application-project-how-to-copy-a-referenced-dlls-dependencies-to

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!