子项目的 App.config 未复制到输出
我有一个包含两个可执行项目的解决方案。
Main.exe
依赖于Sublined.exe
。
这些项目都有 App.config
文件,因此在它们各自的输出目录中,我有 Main.exe.config
和 Subordination.exe.config
。
当我构建 Main.exe
时,Subordination.exe
被复制到 Main 的输出目录中,但 Sublined.exe.config
却没有。
是否有标准方法告诉 Visual Studio 执行此操作?
I have a solution with two executable projects.
Main.exe
is dependent on Subordinate.exe
.
These projects both have App.config
files, so in their respective output directories, I have Main.exe.config
and Subordinate.exe.config
.
When I build Main.exe
, Subordinate.exe
is copied into Main's output directory, but Subordinate.exe.config
is not.
Is there a standard way to tell Visual Studio to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现的另一种方法是将 app.config 文件作为链接文件添加到依赖项目中,例如,在这里,您将在 Main.exe 的项目中添加到 Subordination.exe 的 app.config 的链接,并将其设置为复制到输出构建时的目录。然后,您可以通过编辑项目文件中的
元素来更改在构建时复制到 Main.exe 输出目录的文件的名称,例如
:您必须对生成的配置文件的名称进行硬编码,但这并不比
AfterBuild
方法更糟糕,而且我发现这种方法更加透明,并且它消除了您提到的构建顺序依赖性问题。Another way I found is by adding the app.config file as a linked file to the dependent project, e.g. here you would add a link to Subordinate.exe's app.config into Main.exe's project, and set it to be copied to the output directory when built. You can then change the name of the file that is copied to Main.exe's output directory at build time by editing the
<Link>
element in your project file, something like:This has the same issue that you have to hardcode the name of the generated config file, but that's no worse than the
AfterBuild
approach, and I find this method a little more transparent, and it removes the build-order dependency issue that you mentioned.右键单击
Main
项目并选择编辑项目文件
。添加AfterBuild
事件:Right click on the
Main
project and selectEdit Project File
. Add anAfterBuild
event:看看这个答案(基于@theyetiman的工作)。它主要需要修改
app.config
文件所属的项目。 使用项目保持不变。另请注意,对于 Visual Studio 2017,不再需要进行此修改。如果您打开包含上述解决方法的项目的解决方案,错误窗口中会显示类似于以下内容的警告:
添加一个比较
$(VisualStudioVersion)
的条件以避免此警告并保持向后兼容性:Have a look at this answer (based on work of @theyetiman). It requires mainly a modification of the project, the
app.config
file belongs to. The consuming projects are left unmodified.Also note, that with Visual Studio 2017 this modification is not necessary any more. If you open a solution with a project containing the above workaround, a warning similar to the following is displayed in the errors window:
Add a condition comparing
$(VisualStudioVersion)
to avoid this warning and keep backward compatibility: