简体   繁体   English

MSBuild 未将 Web.config 发布到发布文件夹的根目录

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

I'm running the following MSBuild command from PowerShell to publish a solution file:我从 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

When I check the output folder, the web.config is not present in the root, but I can see it under the "bin" folder.当我检查 output 文件夹时,根目录中不存在 web.config,但我可以在“bin”文件夹下看到它。 The Web.config is currently marked as Content in the csproj file. Web.config 当前在 csproj 文件中标记为内容。

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

I've noticed that if I rename the file (Eg to Web2.config ), then the file appears.我注意到,如果我重命名该文件(例如,将其重命名为Web2.config ),则会出现该文件。 Is this normal MSBuild behaviour?这是正常的 MSBuild 行为吗? How can I force the Web.config to be published to the root of the output path?如何强制将 Web.config 发布到 output 路径的根目录?

Try changing the $msbuildOptions to @msbuildOptions .尝试将$msbuildOptions更改为@msbuildOptions This is called splatting.这称为飞溅。

"Splatting is a method of passing a collection of parameter values to a command as a unit." “Splatting 是一种将参数值集合作为一个单元传递给命令的方法。”

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

& msbuild @msbuildOptions

Sometimes you need a version of the .config for every configuration of your project.有时您需要为项目的每个配置配置一个版本的.config This is dependent on your configuration, if deploy the Release configuration this this would be Web.Release.config .这取决于您的配置,如果部署Release配置,这将是Web.Release.config But i think this version is not a real configuration but rather a xslt file.但我认为这个版本不是真正的配置,而是一个 xslt 文件。

https://learn.microsoft.com/en-us/as.net/core/host-and-deploy/iis/transform-webconfig?view=as.netcore-6.0 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