簡體   English   中英

MSBuild 未將 Web.config 發布到發布文件夾的根目錄

[英]MSBuild not publishing Web.config to the root of the publish folder

我從 PowerShell 運行以下 MSBuild 命令來發布解決方案文件:

$Configuration = "Release"
$slnFullPath = "...\Solution.sln";
$PublishPath = "$RepoRoot\output-path\$Configuration"
$LogVerbosity = "q"
$msbuildOptions = @(
    $slnFullPath
    , "/t:Build"
    , "/p:Configuration=$Configuration"
    , "/p:DeployOnBuild=true"
    , "/p:publishUrl=$PublishPath" 
    , "-detailedSummary"
    , "-m"
    , "/p:BuildInParallel=true"
    , "-nologo"
    , "-binaryLogger:LogFile=$logsPath\$Configuration.binlog"
    , "-verbosity:$LogVerbosity"
    , "/consoleLoggerParameters:ShowTimestamp; ErrorsOnly; ShowEventId; PerformanceSummary; Summary;"
);

Write-Host "Command - & msbuild $msbuildOptions" -ForegroundColor DarkCyan
& msbuild $msbuildOptions

當我檢查 output 文件夾時,根目錄中不存在 web.config,但我可以在“bin”文件夾下看到它。 Web.config 當前在 csproj 文件中標記為內容。

<Content Include="Web.config">
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

我注意到,如果我重命名該文件(例如,將其重命名為Web2.config ),則會出現該文件。 這是正常的 MSBuild 行為嗎? 如何強制將 Web.config 發布到 output 路徑的根目錄?

嘗試將$msbuildOptions更改為@msbuildOptions 這稱為飛濺。

“Splatting 是一種將參數值集合作為一個單元傳遞給命令的方法。”

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_splatting?view=powershell-7.1

& msbuild @msbuildOptions

有時您需要為項目的每個配置配置一個版本的.config 這取決於您的配置,如果部署Release配置,這將是Web.Release.config 但我認為這個版本不是真正的配置,而是一個 xslt 文件。

https://learn.microsoft.com/en-us/as.net/core/host-and-deploy/iis/transform-webconfig?view=as.netcore-6.0

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM