【问题标题】:How to override dotnet publish's web.config?如何覆盖 dotnet publish 的 web.config?
【发布时间】:2022-01-11 18:49:45
【问题描述】:

当我执行 dotnet publish -c Release 时,这个web.config 文件将被添加到我的发布文件夹中:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\aaa.xxxx.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="OutOfProcess" />
    </system.webServer>
  </location>
</configuration>

但是我在服务器上有不同的配置,我想用我自己的配置覆盖它,但是我不知道该怎么做。

我尝试创建web.config 文件并将其设置为Copy always

但我收到:

错误 MSB4018:“TransformWebConfig”任务意外失败。

错误 MSB4018:System.UnauthorizedAccessException:访问路径 'bin\Release\netcoreapp3.1\publish\web.config

即使我以管理员身份运行 dotnet publish -c Release

【问题讨论】:

  • 嗯..它适用于我(VS2019)。如果 web.config 是只读的,我在某处读到它会失败。介意你检查一下你的是否是?
  • 大概就是这个原因吧,我讨厌这个TFVC

标签: c# .net-core dotnet-cli


【解决方案1】:

目前,我使用的解决方法是:

rmdir bin /s /q
rmdir obj /s /q
rmdir output /s /q
dotnet publish -c Release -o output
del /f "output\web.config"
xcopy "prod_web.config" "output\web.config*"
pause

【讨论】:

    猜你喜欢
    • 2021-01-09
    • 2019-11-09
    • 2021-08-26
    • 2012-08-07
    • 1970-01-01
    • 2010-12-31
    • 1970-01-01
    • 2020-03-30
    • 2010-11-30
    相关资源
    最近更新 更多