我在Azure Devops中设置新的构建和部署管道。它是一个较旧的Web应用程序,带有一些web.config的转换文件。在过去,我们将根据环境的数量构建相同的代码x次。当我从这里读到https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/transforms-variable-substitution?view=vsts#xmltransform时,这不再是必要的
看起来部署管道可以从我的转换文件中获取更改。
但问题是我的其他转换文件没有包含在包中,因此我收到以下警告消息:
[warning]Unable to apply transformation for the given package. Verify the following.
[warning]1. Whether the Transformation is already applied for the MSBuild generated package during build. If yes, remove the <DependentUpon> tag for each config in the csproj file and rebuild.
[warning]2. Ensure that the config file and transformation files are present in the same folder inside the package.
当我下载Web工件时,是的。[stage] .config文件不存在建议。
是否有某些设置允许我包含这些文件?还是阻止它们被改造?
MSBuild知道如何根据以下设置/属性/参数(按顺序)transform the web.config文件
dotnet publish --configuration Release
dotnet publish --configuration Release /p:PublishProfile=FolderProfile
dotnet publish --configuration Release /p:EnvironmentName=Production
dotnet publish --configuration Release /p:CustomTransformFileName=custom.transform
我认为开发人员通常只基于构建配置来实现这一点,我相信MSBuild(和dotnet)知道如何基于Web中的<DependentUpon>Web.config</DependentUpon>
元素来执行此操作。项目或构建脚本中的[configuration] .config项目文件。
Azure DevOps Release Pipelines有点不同。在构建/发布项目之后,管道想要转换web.config,如果MSBuild(或dotnet)已经尝试过它,则不知道如何做到这一点。从而:
[警告]无法对给定包应用转换。验证以下内容。 [警告] 1。转换是否已在构建期间应用于MSBuild生成的包。如果是,请删除csproj文件中每个配置的标记并重建。 [警告] 2。确保配置文件和转换文件存在于包内的同一文件夹中。
<DependentUpon>
标记
因此:您需要从csproj中删除标记以防止MSBuild转换文件
或者:您需要将/p:TransformWebConfigEnabled=False
参数用于MSBuild。
(注意:我认为这是正确的,这可以用于删除依赖标签,但我可能是错的)现在,您需要根据File Transforms and Value Substitutions文档组织发布管道。
[部分]开始:IIS Web App部署 ==================================== 任务:IIS Web App部署 描述:使用Web Deploy部署网站或Web应用程序 版本:0.0.51 作者:微软公司 帮助:More information ==================================== ... [命令] C:... \ ctt \ ctt.exe s:C:... \ Web.config t:C:... \ Web.Release.config d:C:... \ Web.config pw一世 [命令] C:... \ ctt \ ctt.exe s:C:... \ Web.config t:C:... \ Web.Development.config d:C:... \ Web.config pw一世 XML转换成功应用 ...
您可以使用XDT Transform任务执行转换操作。
选项2是我走的路线。
以下是该任务对我来说的样子。
该任务将配置放在构建中,然后我可以在发布管道中使用该构建,而无需重建xx次。