子项目的App.config未被复制到输出

Mud*_*Mud 19 app-config visual-studio-2010 visual-studio

我有一个包含两个可执行项目的解决方案

Main.exe依赖于Subordinate.exe.

这些项目都有App.config文件,因此在各自的输出目录中,我有Main.exe.configSubordinate.exe.config.

当我构建时Main.exe,Subordinate.exe被复制到Main的输出目录中,但Subordinate.exe.config不是.

是否有一种标准方法告诉Visual Studio这样做?

adr*_*ian 14

我找到的另一种方法是将app.config文件作为链接文件添加到依赖项目中,例如,在此处您将向Subordinate.exe的app.config添加指向Main.exe项目的链接,并将其设置为复制到输出构建时的目录.然后,您可以通过编辑<Link>项目文件中的元素来更改在构建时复制到Main.exe输出目录的文件的名称,如:

<None Include="..\Subordinate.ProjectFolder\app.config">
  <Link>Subordinate.exe.config</Link>
  <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Run Code Online (Sandbox Code Playgroud)

这有一个问题,你必须硬编码生成的配置文件的名称,但这并不比该AfterBuild方法更糟糕,我发现这个方法更透明,它删除了你提到的构建顺序依赖问题.


KMo*_*raz 10

右键单击Main项目并选择Edit Project File.添加AfterBuild活动:

  <Target Name="AfterBuild">
    <Copy SourceFiles="..\Subordinate\bin\$(Configuration)\Subordinate.exe.config" 
          DestinationFolder="$(TargetDir)" />
  </Target>
Run Code Online (Sandbox Code Playgroud)