从 VS 解决方案内的文件读取
我有一个 xml 文件,我想将其作为模板与我的程序一起包含在内。我希望项目完成后将其与 .exe 捆绑在一起。
这可能吗?
如果是这样,我应该如何在代码中引用它?我认为引用“myXML.xml”不起作用,因为如果包含它,该文件将不再作为独立对象存在。
另一种想法是将内容复制/粘贴到字符串中,但这在很多方面似乎都是一个坏主意。 (共 900 行。)
有什么想法吗?
谢谢。
这背后的真正动机是我真的更喜欢独立的可执行文件,而不是让用户完成安装过程。此外,还有一个额外的好处,那就是他们不太可能搞砸。
I have an xml file that I want to include along with my program as a template. I would prefer that it be bundled with the .exe when the project is completed.
Is this possible?
If so, how should I reference it in the code? I would assume that referencing "myXML.xml" won't work because, if it is included, the file no longer exists as a standalone object.
An alternative idea is to copy/paste the contents into string, but that seems like a bad idea in so many ways. (It's 900 lines.)
Ideas?
Thank you.
The real motivation behind this is I really prefer standalone executables rather than making the user go through the installation process. Additionally there's the extra benefit that they're less likely to f- it up.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这非常简单,您可以将文件存储在任何 .NET 程序集中作为“嵌入式资源”,然后可以在运行时访问它们。
有关如何执行此操作的详细说明,请参阅此处的 Microsoft 文章。
This is quite simple to do, you can store files in any .NET assembly as "Embedded Resources", which can be then accessed at runtime.
See the Microsoft article here for a detailed rundown on how to do this.
另一种方法是资源文件, http://msdn .microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx
Another way is resource files, http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx