【问题标题】:.Net Core 2.2 web.config won't transform LAUNCHER_PATH or LAUNCHER_ARGS on publish in Azure DevOps.Net Core 2.2 web.config 在 Azure DevOps 中发布时不会转换 LAUNCHER_PATH 或 LAUNCHER_ARGS
【发布时间】:2019-09-02 15:02:52
【问题描述】:

我有一个简单的 API 项目,我可以将它推送到 Elastic Beanstalk 并在 IIS 上运行而不会遇到任何问题。 Web.Config(相当标准),如下所示:

<?xml version="1.0" encoding="utf-8"?> 
<configuration>   
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
      </aspNetCore>   
    </system.webServer>
</configuration>

发布此内容时,aspNetCore 标记将被转换,LAUNCHER_PATHLAUNCHER_ARGS 占位符被替换,hostingModel="InProcess" 添加(.csproj 设置为 &lt;AspNetCoreHostingModel&gt;InProcess&lt;/AspNetCoreHostingModel&gt;)到以下内容:

<aspNetCore processPath="dotnet" arguments=".\xxxxxxxx.Api.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess">

我有另一个项目,其中包含完全相同的 web.config 文件,当我手动发布(本地)时它会转换,但通过 Azure DevOps 发布时不会。两种解决方案中的 YML 是相同的(并且都使用 CreateDefaultBuilder),但在第二个项目中,web.config 不会在发布时进行转换,它仍然使用 LAUNCHER_PATHLAUNCHER_ARGS 并且没有设置 hostingModel .

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: False
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

注意:$(BuildConfiguration) 在两个项目(发布)中是相同的。

我可以对 web.config 进行硬编码,因此它不需要转换,但我想知道如何正确解决这个问题(尤其是我们可能希望稍后将它部署到 linux 容器中)。我已经检查过,.csproj 文件具有相同的设置(和包版本),除了 web.config 所在的位置之外,我看不出两个项目之间有什么不同(所以我想我错过了一些东西):

有效的项目:

[SolutionDirectory]\[ProjectDirectory]\web.config

不起作用的项目:

[SolutionDirectory]\src\[ProjectDirectory]\web.config

它可以在本地工作,但不能在 DevOps 中工作,这一事实让我很难过。什么可能导致发布无法转换 web.config?

我应该注意,确实有效的项目在发布任务中设置了projects: '**/*.sln',但是在另一个项目上设置它并不能解决问题(我查看了生成的工件)。

【问题讨论】:

  • 您是否查看了不工作项目的发布任务日志?日志是否显示您的 API 项目已发布?另外,尝试将**/*.sln 更改为**/*.csproj
  • 日志中没有任何线索。使用 .csproj 让它工作。不知道为什么。

标签: c# .net-core azure-devops web-config csproj


【解决方案1】:

.Net Core 2.2 web.config 在 Azure DevOps 中发布时不会转换 LAUNCHER_PATH 或 LAUNCHER_ARGS

在发布任务中设置**/*.sln 时,我无法完全重现您的问题,我得到了不同的结果。但是如果在发布任务中指定项目文件而不是解决方案文件,如&lt;SolutionName&gt;/**/*.csproj。我可以得到与在本地发布相同的结果:

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish
    publishWebProjects: false
    projects: '<SolutionName>/**/*.csproj'
    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'
    zipAfterPublish: True

然后我可以得到两个 .zip 文件,并将它们解压缩,我可以找到 web.config 转换为预期:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\WebAppTransform.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess"></aspNetCore>
  </system.webServer>

</configuration>

希望这会有所帮助。

【讨论】:

  • 如果有机会,我会尝试使用特定的 csproj。我不能使用通配符,因为解决方案中有多个项目。不过,这不是放入 sln 的问题 - 它没有任何区别。
  • 今天有机会重新审视这个问题 - 您设置 CS Proj 的建议解决了这个问题。 projects: '**/xxxxxxxxxxxxxx.Api.csproj' 成功了!
  • 知道为什么这在一个解决方案中会成为问题,而在另一个解决方案中不会?
猜你喜欢
  • 2016-09-24
  • 2019-09-29
  • 1970-01-01
  • 2019-04-20
  • 1970-01-01
  • 1970-01-01
  • 2021-09-19
  • 2019-07-08
  • 1970-01-01
相关资源
最近更新 更多