简体   繁体   English

如何使我的构建将内容从引用的库复制到IIS express文件夹?

[英]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.

相关问题 如何将文件夹(和子文件夹)从解决方案内容复制到IsolatedStorage? - How do I copy folder(and subfolders) from my solution content into IsolatedStorage? 在构建时如何将类库程序集复制到Web项目中? - How do I copy my class library assemblies to my Web project at build time? 如何为从nuget引用的库创建Singleton实例 - How do I create Singleton instance for a library referenced from nuget 如何将我的照片从 tmp 目录文件夹保存到 xamarin iOS 中的库/文档文件夹 - How Do I Save my photo from tmp directory folder to library/ document folder in xamarin iOS 对于我在 Visual Studio 2013 中的类库项目; 使用后期构建事件如何将创建的 dll 复制到另一个路径? - For my class Library project in visual Studio 2013 ; Using post build event how do I copy the created dll to another path? 如何使用 ServerManager 从类库中读取 IIS 站点,而不是 IIS express,或者提升的进程如何处理类库? - How to use ServerManager to read IIS sites, not IIS express, from class library OR how do elevated processes handle class libraries? 如何将文件从引用程序集的结构复制到本地结构 - How do i copy files from a referenced assembly's structure to the local structure NLog.Config从IIS Express文件夹而不是Content Root读取 - NLog.Config read from IIS Express folder instead of Content Root 如何使VS自动将文件夹复制到构建目录? - How to make VS copy a folder to the build directory automatically? 无法从解决方案访问IIS Express文件夹 - Unable to reach IIS Express folder from solution
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM