2013-04-23 164 views
2

我有一個xml文件,saml.config包含一些saml信息。這些信息需要在發佈版本中進行轉換,以包含生產網址,而不是開發和分級網址。在我的開發和分期環境中,轉換完全發生,在發佈環境中,轉換不需要。AppHarbor自定義配置文件轉換

我一直在試用http://webconfigtransformationtester.apphb.com/來測試變換,但它們沒有被應用,但是VS又一次地應用了它們。

基礎saml.config文件:

<?xml version="1.0"?> 
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration"> 
    <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="http://localhost:49462/SingleSignOn/ConsumeAssertion"/> 
    <PartnerIdentityProvider Name="MTMIdentity" 
          SignAuthnRequest="false" 
          WantResponseSigned="false" 
          WantAssertionSigned="false" 
          WantAssertionEncrypted="false" 
          SingleSignOnServiceUrl="https://identity.*********.com/SingleSignOn/"/> 
</SAMLConfiguration> 

轉換文件:

<?xml version="1.0" encoding="utf-8" ?> 
<SAMLConfiguration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform" xmlns="urn:componentspace:SAML:2.0:configuration"> 
    <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="https://***********.com/SingleSignOn/ConsumeAssertion" xdt:Transform="SetAttributes" xdt:Locator="Match(Name)" /> 
</SAMLConfiguration> 

結果應替換爲*******服務提供商AssertionConsumerServiceUrl本地主機URL ****。com版本,但它不是

<?xml version="1.0"?> 
<SAMLConfiguration xmlns="urn:componentspace:SAML:2.0:configuration"> 
    <ServiceProvider Name="Portal.Web" AssertionConsumerServiceUrl="http://localhost:49462/SingleSignOn/ConsumeAssertion" /> 
    <PartnerIdentityProvider Name="MTMIdentity" SignAuthnRequest="false" WantResponseSigned="false" WantAssertionSigned="false" WantAssertionEncrypted="false" SingleSignOnServiceUrl="https://identity.********.com/SingleSignOn/" /> 
</SAMLConfiguration> 

爲什麼變換測試儀不適用轉化?

編輯:

我要補充一點,我使用SlowCheetah插件/ NuGet包來處理在本地和我們的臨時環境的轉變。

考慮到文檔(http://support.appharbor.com/kb/getting-started/managing-environments)指出

配置文件轉化爲支持對具有相應.release.config文件中的所有.config文件。

我認爲AppHarbor可以在沒有SlowCheetah的情況下做到這一點。但是,WebConfigTransformTester工具再次不適用此轉換。

所以問題仍然是,我該如何應用這種轉換?我可以在AppHarbor中使用SlowCheetah嗎?

編輯:

經進一步調查,看來AppHarbor不應用轉換到Web.config爲好。

我CONFIGS:

enter image description here

的AppSettings在Web上。配置

<appSettings> 
    <add key="webpages:Version" value="2.0.0.0" /> 
    <add key="webpages:Enabled" value="false" /> 
    <add key="aspnet:UseHostHeaderForRequestUrl" value="true" /> 
    <add key="PreserveLoginUrl" value="true" /> 
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" /> 
    <add key="Environment" value="Development" /> 
</appSettings> 

注意環境被設置爲 「發展」

釋放轉型:

<?xml version="1.0"?> 
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> 
    <appSettings> 
     <add key="Environment" value="Release" xdt:Transform="SetAttributes" xdt:Locator="Match(key)" /> 
    </appSettings> 
    <system.web> 
     <compilation xdt:Transform="RemoveAttributes(debug)" /> 
     <customErrors defaultRedirect="GenericError.htm" mode="Off" xdt:Transform="Replace"> 
      <error statusCode="500" redirect="InternalError.htm"/> 
     </customErrors> 
    </system.web> 
</configuration> 

注意環境被替換爲 「釋放」

的AppHarbor環境:

enter image description here

在部署到AppHarbor之後,我下載了構建並檢查了Web.Config,它仍然具有「開發」環境設置。

編輯:

我添加了一個行動,以我的控制器的一個讀取環境AppSetting,並輸出到視圖,出乎我的意料,這是「釋放」!

那麼是什麼給? 「下載構建」內容沒有適當的轉換,但是當請求發生時,它會發生什麼? AppHarbor何時應用轉換?它是在運行時而不是在構建過程中?

編輯:

從AppHarbor傢伙聽到背部和轉型發生在實際的發佈,所以即使搭建了一個「發佈網站」文件夾,它仍然不是發佈的最終輸出動作。

謝謝, 喬

回答

0

來發現,回答我原來的問題爲方式的轉變沒有發生,是因爲XMLNS在配置文件中的根節點屬性。

不幸的是,http://webconfigtransformationtester.apphb.com/沒有提供任何關於爲什麼沒有進行轉換的信息,但是如果您仔細查看代碼,可以看到有一個記錄器可用,但它被設置爲空。

我最終拉動了代碼並添加了一個記錄器,並發現警告「源文檔中沒有元素匹配'/ SAMLConfiguration'」。進一步挖掘我發現這篇文章Why does this web.config transform say it can't find the applicationSettings element?,在Sayed的回答中,他指出,較舊的MSBuild轉換任務不符合xmlns屬性。

從配置文件和轉換文件中刪除xmlns屬性應該可以解決問題。

但是,在我的情況下,xmlns屬性是必需的,無法刪除。

因此,直到AppHarbor更新他們的轉換程序集以使用MSBuild v11.0程序集,我幾乎停滯不前。