2013-08-30 52 views
6

我通過nuget安裝了SlowCheetah包,併爲我的web.config添加了基於構建配置的轉換文件。 但是,在構建時,web.config不會被轉換。我檢查了我的項目文件,並看到SlowCheetah PropertyGroup和Import元素的條目。我沒有看到項目文件中的轉換目標。 如果我添加一個app.config,app.config文件確實會被轉換。 我的理解是,安裝SlowCheetah軟件包應自動將web.config變換目標添加到項目的MSBuild文件。我可以手動添加它,但我認爲SlowCheetah可以實現。 我錯過了什麼。請讓我知道。 我的要求是我的web.config文件應該基於構建配置進行轉換,並且轉換後的web.config文件應位於輸出目錄中。 謝謝並感謝所有幫助。SlowCheetah沒有轉換構建012.網站上的web.config

回答

0

您是否已將轉換文件的「複製到輸出目錄」屬性設置爲「不要複製」? 請檢查您的項目文件。

在項目文件中應添加以下條目(取決於你安裝的版本,在這種情況下2.5.7):

<PropertyGroup Label="SlowCheetah"> 
<SlowCheetah_EnableImportFromNuGet Condition=" '$(SC_EnableImportFromNuGet)'=='' ">true</SlowCheetah_EnableImportFromNuGet> 
<SlowCheetah_NuGetImportPath Condition=" '$(SlowCheetah_NuGetImportPath)'=='' ">$([System.IO.Path]::GetFullPath($(MSBuildProjectDirectory)\..\packages\SlowCheetah.2.5.7\tools\SlowCheetah.Transforms.targets))</SlowCheetah_NuGetImportPath> 
<SlowCheetahTargets Condition=" '$(SlowCheetah_EnableImportFromNuGet)'=='true' and Exists('$(SlowCheetah_NuGetImportPath)') ">$(SlowCheetah_NuGetImportPath)</SlowCheetahTargets> 

<Import Project="$(SlowCheetahTargets)" Condition="Exists('$(SlowCheetahTargets)')" Label="SlowCheetah" /> 
+1

對於任何人看,這是100%不正確的SlowCheetah的當前版本。 – EKW

9

Visual Studio是在做轉型,只有當您可以使用發佈功能部署項目。要做到這一點,你需要調整你的MSBuild腳本。完整的解決方案是here。這裏的要點:項目

文件創建一個名爲Web.Base.config文件,除了 現有Web.Debug.config和Web.Release.config。這個文件將是 相當於您的舊Web.config,因爲它將成爲轉換的基礎。您將以這些文件結束:

Web.config,Web.Base.config,Web.Debug.config,Web.Release.config和 Web.config。添加下面的配置到你的 的.csproj文件的底部,只是收盤前 - 標籤:

<Target Name="BeforeBuild"> 
    <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" /> 
</Target> 

最新動態:在我認識的評論提醒我們,我也有一個問題 在發佈 項目時,使用Visual Studio將XML轉換兩次。這個問題的解決是一個條件添加到 目標標籤是這樣的:

<Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''"> 
+2

關於解決方案,對於Visual Studio 2013,由於任務已經導入,因此您不需要。 – MikeJansen

+0

感謝分享。 –

+0

yas yas yas ! – TWilly

3

爲了詳細說明菲利普的回答我發現了一個可能的簡單的解決方案: 無需一個Web.Base.Config並沒有問題覆蓋你的web.config導致源代碼管理中的問題。

BeforeBuild:將目標設爲TargetDir和TargetFileName。

AfterBuild:在構建完成後,將其複製到您的已發佈網站。

<Target Name="BeforeBuild"> 
<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="$(TargetDir)$(TargetFileName).config" /> 
</Target> 
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Dev' Or '$(Configuration)' == 'Test' Or '$(Configuration)' == 'Prod'"> 
    <Delete Files="$(TargetDir)_PublishedWebsites\$(ProjectName)\Web.config" /> 
    <Copy SourceFiles="$(TargetDir)$(TargetFileName).config" DestinationFiles="$(TargetDir)_PublishedWebsites\$(ProjectName)\Web.config" /> 
</Target> 
+0

您可以詳細說明爲什麼構建不會替換構建之前在那裏複製的配置文件?因爲我無法得到這個工作,我認爲這是因爲文件被覆蓋。 –

相關問題