加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 引用时将app.config从类库导入到项目中

发布时间:2020-12-15 17:25:01 所属栏目:百科 来源:网络整理
导读:我有一个类库,在app.config中有设置. 我知道任何使用此库的项目都需要在其自己的app.config中进行设置. 有没有办法将库中的设置作为模板/默认配置设置? 我想给项目一个起点,但也允许他们覆盖特定配置以满足他们的需求. 我很感激你的帮助! 解决方法 我过去
我有一个类库,在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 PathToReferenceLibaryApp.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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读