2

我有一个控制台应用程序,它使用在 app.config 中定义的数据库连接字符串。我有一些转换来根据构建配置更改字符串。

我还有一些将 app.config 复制到其他项目输出的构建后事件。问题是构建后事件首先触发,我复制了未转换的 app.config。后来转换任务开始并应用转换(所以我知道它有效)。我使用 Visual Studio 2010 和 .NET 4。

现在动作是 [1]、[ 3 ]、[ 2 ],我需要将它们重新排序为 [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>

任何帮助将不胜感激

4

2 回答 2

1

如果无法重新排序它们,您可以将它们组合起来。在构建后事件中进行转换(在顶部)。但是,命令提示符语法中没有任何好的 xml 转换方法(据我所知)。您可以让它调用您自己的 xml 转换可执行文件/批处理文件,并将您的文件名和转换名称作为参数传递给它。

如果您不想创建自己的实用程序,那里有很多

于 2012-04-25T23:58:12.620 回答
1

您可以将它们复制为转换目标的一部分,而不是使用构建后事件来复制文件。

在上述 XML 中使用之前的任务。请参阅http://msdn.microsoft.com/en-us/library/3e54c37h.aspx

于 2012-04-26T09:24:45.520 回答