我有一个类库,在app.config中有设置.
我知道任何使用此库的项目都需要在其自己的app.config中进行设置.
有没有办法将库中的设置作为模板/默认配置设置?
我想给项目一个起点,但也允许他们覆盖特定配置以满足他们的需求.
我很感激你的帮助!
最佳答案 我过去也需要这样做;我记得当时我做的研究无法将文件标记为“必需”并与参考一起复制.来自其他论坛和MSDN的建议是在最终位置手动合并App.config文件.
解决方案我最终用作启动/默认项目的后期构建脚本,将App.Config文件XCOPY到正确的目标目录中.这对我的情况很有效,因为我已经有一个后构建脚本来执行其他任务.
如果确实有更好/更清洁的解决方案,我会有兴趣听到它.
编辑:下面是我的构建后脚本的简化版本.希望能帮助到你.
@ECHO OFF
SETLOCAL
:: VISUAL STUDIO USAGE
:: $(ProjectDir)..\PostBuild.bat $(TargetName) $(TargetDir) $(ProjectDir) $(ConfigurationName)
SET TargetName=%1
SET TargetDir=%2
SET ProjectDir=%3
SET Configuration=%4
:: XCOPY Usage
:: /I If destination does not exist and copying more than one file, assumes that destination must be a directory.
:: /F Displays full source and destination file names while copying.
:: /Y Suppresses prompting to confirm you want to overwrite an existing destination file.
:: /D Copy only those files whose source time is newer than the destination time.
:: /R Overwrites read-only files.
:: /S Copies directories and subdirectories except empty ones.
:: /E Include empty directories
:: MOVE Usage
:: /Y Suppresses prompting to confirm you want to overwrite an existing destination file.
:: Copy the *.config to output
ECHO F | XCOPY /F /Y /R PathToReferenceLibary\App.config %TargetDir%ReferenceLibary.dll.config
:CLEAN
ECHO =============================================================
ECHO == Clean Unwanted Files
ECHO =============================================================
:: Delete unnecessary default App.config
DEL /Q %TargetDir%App.config
:: Delete license files as they should *never* be shipped!
DEL /Q %TargetDir%*.lic
:EXIT
EXIT ERRORLEVEL