[英]How do I make my build copy content from a referenced library to IIS express folder?
I have a class library which makes reference to an xml file inside of a folder within the project called Content. 我有一个类库,该类库引用了名为Content的项目中的文件夹内的xml文件。
I have an MVC4 project that references the above class library and it needs information from that xml file. 我有一个引用上述类库的MVC4项目,它需要该xml文件中的信息。
When I run the MVC project (via IIS express), I get an error stating that it cannot find the xml file in the IIS directory. 当我运行MVC项目(通过IIS express)时,收到一条错误消息,指出它无法在IIS目录中找到xml文件。
I tried setting that file to "Copy Always" and the build action to "Embedded Resource" but it's not working. 我尝试将文件设置为“始终复制”,并将构建操作设置为“嵌入式资源”,但是它不起作用。 If I copy the Content folder from the bin\\debug directory of the class library to my IIS express folder, it'll work
如果将Content文件夹从类库的bin \\ debug目录复制到IIS express文件夹中,它将可以正常工作
How do I set it so that it always has the content when I run my MVC application? 在运行MVC应用程序时,如何设置它使其始终包含内容?
The solution structure looks like this at the moment: 目前,解决方案结构如下所示:
对于我的项目,我在相同情况下将BuildAction设置为EmbeddedResource,并且可以正常工作。
Try using System.Reflexion, so the file is embeded on the dll then you can useit from there. 尝试使用System.Reflexion,以便将该文件嵌入dll中,然后可以从那里使用它。
Assembly assembly = Assembly.GetExecutingAssembly();
Stream strXml = assembly.GetManifestResourceStream("App.Dir.File.xml"));
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(strXml);
"App.Dir.File.xml" refer the name space where the file are. “ App.Dir.File.xml”引用文件所在的名称空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.