我想引用Windows服务和ASP.NET MVC网站之间的一些常见配置设置。我通过App.config或Web.config(分别)中的appSettings使用文件属性来做到这一点。被引用的文件(名为common.config)是同一解决方案中单独项目中的链接文件。该common.config设置为内容与始终复制在两个项目。在应用程序或Web配置中使用链接文件的AppSettings
This stack answer to a similiar question似乎暗示至少对于configSource这个解决方案是可行的。我不想要configSource,但我只想在这两个项目中使用少数几个属性。 更新:我刚试过这个,并且configSource也不起作用。它无法找到配置文件。这导致我相信common.config不会被视为与复制总是内容。
实施例的App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings file="common.config">
<add key="NotCommonKey" value="1"/>
</appSettings>
</configuration>
实施例的Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings file="common.config">
<add key="NotCommonKey2" value="2" />
</appSettings>
</configuration>
例common.config(内容 - >一直拷贝)
<appSettings>
<add key="CommonKey" value="1" />
</appSettings>
我正在使用ConfigurationManager/WebConfigurationManager从读取AppSettings属性。
任何想法为什么当common.config是一个链接文件,它的AppSettings值不会被使用,当它没有被链接时,它的工作原理是正常的?
谢谢!
1.您确定common.config与您的其他配置文件位于同一个文件夹中吗? 2.任何对common.config的更改都不会反映在您的应用中,除非您重新启动。 –
1.我确实认为这是问题所在。我认为出于某种原因,当我运行调试时,即使将它设置为复制文件,也不会将链接的common.config复制到Web应用程序/控制台应用程序文件夹中。 – scottheckel
我注意到,如果我创建一个控制台应用程序,它使用驻留在另一个项目中的链接配置文件,它可以工作。它必须特定于web.config文件。我在CodePlex上为此创建了一个问题https://aspnet.codeplex.com/workitem/10351 – scottheckel