gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 12:33:05 25 4
gpt4 key购买 nike

我有一个在 app.config 中有设置的类库。

我知道任何使用这个库的项目都需要在它自己的 app.config 中进行设置。

有没有办法将库中的设置作为模板/默认配置设置?

我想为项目提供一个起点,但也允许他们根据需要覆盖特定配置。

非常感谢您的帮助!

最佳答案

我过去也需要这样做;我从当时所做的研究中回想起,无法将文件标记为“必需”并与引用资料一起复制。来自其他论坛和 MSDN 的建议是在最终位置手动合并 App.config 文件。

我最终在启动/默认项目上用作构建后脚本的解决方案是 XCOPY App.Config 文件到正确的目标目录中。这对我的情况很有效,因为我已经有一个构建后脚本来执行其他任务。

如果确实有更好/更清洁的解决方案,我很想听听。

编辑:下面是我的构建后脚本的精简版。

@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

关于c# - 引用时从类库导入app.config到项目中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9933239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com