简体   繁体   English

如何在 Web Publish 发布包中包含类库的 App.Config 文件

[英]How to Include an App.Config file of a Class Library in the Web Publish release package

I have ran into a scenario where I have added an App.Config file in a Class Library which I am referencing from my ASP.NET MVC project .我遇到了一个场景,我在我从我的ASP.NET MVC 项目中引用的类库中添加了一个App.Config文件。

Now while publishing my Web project I can only see the DLL of the class library in the Bin folder but not the App.Config of the same.现在,在发布我的 Web 项目时,我只能在 Bin 文件夹中看到类库的 DLL,而看不到相同的 App.Config。 Is there any way to include that in the Web publish.有什么方法可以将其包含在 Web 发布中。

Thanks谢谢

You need to tell the compiler to copy these files to the output directory.您需要告诉编译器将这些文件复制到输出目录。 To do so, select the app.config from the solution explorer and hit F4 for properties and select Copy Always like the below example为此,请从解决方案资源管理器中选择app.config并按F4获取properties并选择始终复制,如下例所示

在此处输入图片说明

Your class library shouldnt be using the app.config file.您的类库不应使用 app.config 文件。 Instead the driver application or consuming application should be having a single app.config and should feed this dll with parameters.相反,驱动程序应用程序或消费应用程序应该只有一个 app.config 并且应该为这个 dll 提供参数。

This will also help your application being more SOLID.这也将帮助您的应用程序更加可靠。 Your class library should be doing single job.你的类库应该做单一的工作。 Reading from a app.config file adds a second responsibility.从 app.config 文件读取增加了第二个责任。

Also, class library not reading from the app.config file make your class library loosely coupled and it can be taken anywhere.此外,不从 app.config 文件读取的类库会使您的类库松散耦合,并且可以在任何地方使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM