2011-07-26 47 views
2

我有一個控制檯應用程序,它使用在app.config中定義的數據庫連接字符串。根據構建配置,我有幾個轉換來更改字符串。如何在PostBuildEvents之前先運行app.config轉換任務?

我也有一些後期構建事件,將app.config複製到其他項目輸出。 問題是後構建事件首先觸發,我複製未轉換的app.config。後來轉型任務開始並應用轉型(所以我知道它的工作原理)。我用Visual Studio 2010和.NET 4

使用現在的行動[1],[],[],我需要將它們重新排序爲[1],[2] [3]

1)構建
2)運行變換
3)運行後生成事件

下面是從.csproj的

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> 
    <Target Name="Transformation" Condition="exists('app.$(Configuration).config')" > 
    <TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" /> 
    <ItemGroup> 
     <AppConfigWithTargetPath Remove="app.config" /> 
     <AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config"> 
     <TargetPath>$(TargetFileName).config</TargetPath> 
     </AppConfigWithTargetPath> 
    </ItemGroup> 
    </Target> 
我的變換

這是我生成後事件

<PropertyGroup> 
    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent> 
    </PropertyGroup> 

<PropertyGroup> 
    <PostBuildEvent>copy $(ProjectDir)app.config $(OutDir)\TH.Presentation.LocalAgent\$(TargetFileName).config 
copy $(ProjectDir)app.config $(OutDir)\TH.Services\$(TargetFileName).config</PostBuildEvent> 
    </PropertyGroup> 

任何幫助,將不勝感激

回答

1

如果沒有他們重新排序的方式,你可以將它們結合起來。在生成後事件內部進行變換(在頂部)。但是,在命令提示語法中沒有任何不錯的xml轉換方法(我知道)。你可以讓它調用你自己的xml轉換可執行文件/批處理文件,將它的文件名和變換名稱作爲參數傳遞給它。

如果你不想創建自己的工具,也有使用後生成事件,你可以將它們拷貝複製文件作爲變換目標的一部分,大量的出there

相關問題