.Net Core 2.2 web.config 在 Azure DevOps 中发布时不会转换 LAUNCHER_PATH 或 LAUNCHER_ARGS
.Net Core 2.2 web.config won't transform LAUNCHER_PATH or LAUNCHER_ARGS on publish in Azure DevOps
我有一个简单的 API 项目,我可以毫不费力地将它推送到 IIS 上的 Elastic Beanstalk 和 运行。 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_PATH
和 LAUNCHER_ARGS
占位符并添加了 hostingModel="InProcess"
(.csproj 设置为 <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
) 到以下内容:
<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_PATH
和 [=20] =] 并且没有设置 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 中无效,这让我很困惑。什么会导致 publish 不转换 web.config?
我应该注意到,确实有效的项目在发布任务中设置了 projects: '**/*.sln'
,但是在其他项目上设置此设置并不能解决问题(我查看了生成的工件)。
.Net Core 2.2 web.config won't transform LAUNCHER_PATH or LAUNCHER_ARGS on publish in Azure DevOps
在发布任务中设置 **/*.sln
时,我无法完全重现您的问题,我得到了不同的结果。但是如果在发布任务中指定项目文件而不是解决方案文件,如<SolutionName>/**/*.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>
希望这对您有所帮助。
我有一个简单的 API 项目,我可以毫不费力地将它推送到 IIS 上的 Elastic Beanstalk 和 运行。 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_PATH
和 LAUNCHER_ARGS
占位符并添加了 hostingModel="InProcess"
(.csproj 设置为 <AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
) 到以下内容:
<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_PATH
和 [=20] =] 并且没有设置 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 中无效,这让我很困惑。什么会导致 publish 不转换 web.config?
我应该注意到,确实有效的项目在发布任务中设置了 projects: '**/*.sln'
,但是在其他项目上设置此设置并不能解决问题(我查看了生成的工件)。
.Net Core 2.2 web.config won't transform LAUNCHER_PATH or LAUNCHER_ARGS on publish in Azure DevOps
在发布任务中设置 **/*.sln
时,我无法完全重现您的问题,我得到了不同的结果。但是如果在发布任务中指定项目文件而不是解决方案文件,如<SolutionName>/**/*.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>
希望这对您有所帮助。