带类库项目的ASP.NET解决方案 [英] ASP.NET solution with class library project

查看:60
本文介绍了带类库项目的ASP.NET解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS 2008中有一个解决方案,其中包含两个类库项目和一个ASP.NET网站.ASP.NET站点引用了类库,并且其中一个库包含LINQ To SQL项.

I have an solution in VS 2008 which contains two class library projects and an ASP.NET web site. The ASP.NET site references the class libraries and one of the libraries contains a LINQ To SQL item.

我的问题是关于类库中的app.config,其中包含数据库的连接字符串.构建项目时,此app.config不在构建目录中,这意味着我无法动态更改已部署项目的连接字符串.

My question is with regards to the app.config in the class library which contains the connection string for the database. When I build the project, this app.config isn't within the build directory and this means I can't dynamically change the connection string for the deployed project.

我在做什么错了,如何也可以部署这些设置,以便可以更改连接字符串?

What am I doing wrong here, how can I have these settings deployed too so I can make changes to the connection string?

预先感谢

马丁.

推荐答案

一开始,这也使我有些困惑.

This caused me a bit of confusion at first as well.

您可能会认为类库使用了它自己的项目中包含的app.config文件,但没有使用.它使用引用它的项目的配置文件.

You might think that the class library uses the app.config file that's contained in it's own project but it doesn't. It uses the config file of the project that is referencing it.

因此,您需要做的是在ASP.Net项目的web.config文件中查找< appSettings/> 标记,然后将其更改为< appSettings></appSettings> 并添加库项目的app.config文件中包含的< add .../> 标记.您无需更改代码中的任何内容即可让ConfigurationManager类解决此问题.它知道在哪里看起来很神奇.

So what you need to do is look for the <appSettings/> tag inside the web.config file of your ASP.Net project and change it to <appSettings></appSettings> And add the <add ... /> tags that are contained in the app.config file of the library project. You don't need to change anything in your code for the ConfigurationManager class to figure this out. It knows where to look automagically.

希望如此.

这篇关于带类库项目的ASP.NET解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆