2016-12-28 73 views
0

我有一个包含网站项目(以及其他项目类型)的解决方案文件。它使用发布配置文件进行部署,我试图将整个事件转移到TFS(2015)以自动执行构建和部署过程。如上所述here我无法管理构建配置,因为它是一个网站项目,因此无法使用Web.config Transformation feature手动配置转换为TFS构建步骤

我想执行某种转换,也许作为构建步骤。我可以手动创建和维护web.release.config文件,但不知道如何手动转换它。 XLST文件是否存在将其转换到Visual Studio之外(例如,用于调用XSLT处理器的cmd构建步骤)?

附录:转换成web项目中最肯定会解决这个问题,但不适合我作为一个解决方案需要从有利于我们的代码库远程承包商参与 - 一个TFS生成级解决方案是唯一的事情我在找。

+0

您应该将项目更改为Web应用程序以获得更多功能以及应用程序的稳定性和一致性。 –

+0

CeCe的解决方案是否能解决您的问题? –

+0

我不认为它会,因为它需要一个额外的基本文件(导致在开发过程中使用的web.config在构建过程中不被引用),或者它需要将令牌存储在web.config中文件本身,在开发过程中渲染web.config是无用的,除非只添加了本地后构建步骤,也可以在本地执行替换令牌(如果我正确理解插件)。 – mlhDev

回答

0

因为我的实际转换相对简单的我开发了这个XSL转换:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
    exclude-result-prefixes="msxsl"> 
    <xsl:output method="xml" indent="yes"/> 
    <xsl:variable name="xformPath">web.Prod.config</xsl:variable> 
    <xsl:variable name="xform" select="document($xformPath)"></xsl:variable> 

    <xsl:template match="@* | node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@* | node()"/> 
    </xsl:copy> 
    </xsl:template> 

    <xsl:template name="output-transform"> 
    <xsl:param name="xformNode" /> 
    <xsl:variable name="key" select="@key" /> 
    <xsl:choose> 
     <xsl:when test="$xformNode"> 
     <xsl:copy-of select="$xformNode" /> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

    <xsl:template match="/configuration/appSettings/add"> 
    <xsl:variable name="key" select="@key" /> 
    <xsl:call-template name="output-transform"> 
     <xsl:with-param name="xformNode" select="$xform/configuration/appSettings/add[@key=$key]" /> 
    </xsl:call-template> 
    </xsl:template> 

    <xsl:template match="/configuration/connectionStrings/add"> 
    <xsl:variable name="name" select="@name" /> 
    <xsl:call-template name="output-transform"> 
     <xsl:with-param name="xformNode" select="$xform/configuration/connectionStrings/add[@name=$name]" /> 
    </xsl:call-template> 
    </xsl:template> 

    <xsl:template match="/configuration/system.web/customErrors"> 
    <xsl:call-template name="output-transform"> 
     <xsl:with-param name="xformNode" select="$xform/configuration/system.web/customErrors" /> 
    </xsl:call-template> 
    </xsl:template> 
</xsl:stylesheet> 

这具有一些明显的缺点,

  • 项目要更换必须手动定义
  • 替换整个元素,不仅指定的属性
  • 不维护儿童元素(例如我试图改变system.web/[email protected]false但我失去了我所有的system.web/compilation/assemblies项)

我计划增加这一个命令行一步,我的Visual Studio生成步骤和复制文件的步骤之间,并呼吁无论是MSXSL.EXE或撒克逊的HE变换引擎。

0

作为@MrHinsh在评论中提到,建议创建Web应用程序项目而不是Web站点项目,因为Web站点项目默认情况下没有web.release.config文件,而Web应用程序项目有。

要替换具有变量值的文件中的标记,您可以在构建定义中添加Replace Tokens任务。

enter image description here