本文介绍了如何在PostBuildEvents之前先运行app.config转换任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a console application that uses a database connection string which is defined in app.config. I have a few transformations to change the string depending on the build configuration.

我还有一些构建后事件,这些事件会将app.config复制到其他项目输出中. 问题是先触发构建后事件,然后我复制未转换的app.config.之后,转换任务开始并应用转换(因此我知道它可以工作).我使用Visual Studio 2010和.NET4.

I also have a few post-build events that copy app.config to other projects output. The problem is post-build event fires first and I copy the untransformed app.config. Later the transformation task kicks in and apply the transformation (so I know it works). I use with Visual Studio 2010 and .NET 4.

现在动作是[1],[ 3 ],[ 2 ],我需要将它们重新排序为[1],[2],[3 ]

Right now the actions are [1], [3], [2], I need to reorder them to [1], [2], [3]

1)构建
2)运行转换
3)运行构建后事件

1) Build
2) Run transformation
3) Run post-build event

这是我从.csproj转换

Here is my transformation from .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>

任何帮助将不胜感激

推荐答案

您可以使用转换后的事件来复制文件,而不必使用构建后事件来复制文件.

Instead of using a post build event to copy the files you can copy them as part of the Transformation target.

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

Use the task just before in your above XML.See http://msdn.microsoft.com/en-us/library/3e54c37h.aspx

这篇关于如何在PostBuildEvents之前先运行app.config转换任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:22