繁体   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