I have a Dll which is added into another solution now my code for reading开发者_JAVA百科 the configuration file is in DLL
But my configuration file is in current solution
what should be the proper solution ?
DLL's in .NET cannot have their own configuration - that your.dll.config
file will not be used and interpreted.
The basic premise in .NET configuration is that the host application (your main EXE) should have all its configuration in its app.exe.config
file. So you need to copy & paste your DLL config into the main app's app.config
file and you should be fine.
See this other SO question with a great, lengthy explanation by Chris Ammerman of why having a DLL config isn't as trivial as it may seem at first....
If you're talking about using a .NET assembly and its configurations in another VS project or solution, you can put the configurations in the config file of the new project.
If you're using an auto-generated strongly-typed settings section, you'll need to copy the entire settings section and the configSections declaration for it as well:
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<!-- VB-generated settings section -->
<section name="HappyFunTime1.My.MySettings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- C#-generated settings section -->
<section name="HappyFunTime2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
</configSections>
<applicationSettings>
<HappyFunTime1.My.MySettings>
<setting name="MySetting1" serializeAs="String">
<value>Joy!</value>
</setting>
</HappyFunTime1.My.MySettings>
<HappyFunTime2.Properties.Settings>
<setting name="MySetting1" serializeAs="String">
<value>Joy!</value>
</setting>
</HappyFunTime2.Properties.Settings>
</applicationSettings>
If you're using appSettings, you can copy them into the new project's appSettings section.
With that said, I agree with marc_s; please do read the article he references.
精彩评论