开发者

FileNotFoundException on resource when executing from outside path

开发者 https://www.devze.com 2023-01-05 08:07 出处:网络
The problem we are experiencing was noticed in msbuild. We have an executable in a task that is throwing a FileNotFoundException. This LoadData.exe uses NHibernate to initialize data, so there is an N

The problem we are experiencing was noticed in msbuild. We have an executable in a task that is throwing a FileNotFoundException. This LoadData.exe uses NHibernate to initialize data, so there is an NHibernate.config file in the root of the project.

The properties on the config are set to Content/Copy Always. I can confirm that, on build, this config file is copied to the output directory.

In a console window, you can launch this executable from within the bin/debug directory, and it will work without an error. From outside of this directory, you get a FileNotFoundExcep开发者_如何学JAVAtion on the config file.

The error indicates that the NHibernate.config is being loaded relative to where we are executing MSBUILD in the BUILD directory, and not the LoadData.exe directory. Why is that? Can't we make it absolute to the exe?

Is there a BuildAction setting for this?


Change your code to load the file from the location of your assembly.

0

精彩评论

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

关注公众号