2016-12-28 74 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