我有一個控制檯應用程序,它使用在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>
任何幫助,將不勝感激