当 PowerShell 脚本更新时,Doxygen 不读取 Doxyfile

Doxygen doesn't read Doxyfile when PowerShell scripts updates it

美好的一天 Whosebug。

正如标题所说,我对 Doxygen 有疑问。

描述

PowerShell 脚本修改我的 Doxyfile 的 PROJECT_NUMBER 变量。

然后它运行 Doxygen,但它在 HTML 和 LaTeX 中生成文档,就像它正在读取默认生成的 Doxyfile。

如果我手动修改 Doxyfile before 运行 这个脚本,通过 Notepad++,Doxygen 工作完美,但是一旦脚本是 运行,问题出现。

我还要提到我的 Doxyfile 有:

在实践中,Doxygen 的行为如下:

.\doxygen.exe -g

\doxygen.exe .\Doxyfile

奇怪的行为现在开始了!

让我们调用我实际的 Doxyfile CustomConfig 和默认生成的 DefaultConfig.

如果我通过 .\doxygen.exe -g 生成一个 DefaultConfig,然后我通过 Notepad++ 用 CustomConfig 的文本覆盖它的内容,doxygen 接受 Doxyfile,它应该,并生成一个正确输出!

所以问题不在于 Doxyfile 内容,而是修改文件的 PowerShell。

我通过简单复制和粘贴整个内容验证了这一点:

PowerShell 脚本

# Replace the old PROJECT_NUMBER with the new one
$DOXY_PATH   = $env:FS_OS + "\doc"
$CONFIG_PATH = $DOXY_PATH + "\bin\Doxyfile"
$BIN_PATH    = $DOXY_PATH + "\bin\doxygen.exe"

$GIT_PATH    = $env:FS_OS
$GIT_BRANCH  = "Development"

# Get git commit number on the specified branch
$GIT_HASH   = git log $GIT_BRANCH -1 --pretty=format:%H

$PRJ_CONTENT = Get-Content $CONFIG_PATH
$PRJ_NUM = "PROJECT_NUMBER         = " + $GIT_HASH
$PRJ_CONTENT = $PRJ_CONTENT -replace "PROJECT_NUMBER\s*=\s*[A-z0-9]{40}",$PRJ_NUM
$PRJ_CONTENT | Out-File -FilePath $CONFIG_PATH

Start-Process -FilePath $BIN_PATH -ArgumentList "$CONFIG_PATH" -WorkingDirectory ($DOXY_PATH + "\bin")

复制粘贴脚本

$var = Get-Content "./doc/bin/Doxyfile.bak"
$var | Out-File -FilePath "./doc/bin/Doxyfile"

感谢@BenH 的评论,我找到了解决方案。

看起来 PowerShell 会使用 BOM 自动写入文件。

我从这个问题中找到了已接受答案的解决方案:

Using PowerShell to write a file in UTF-8 without the BOM