我的解决方案中有超过 100 个项目,现在我必须向大多数项目添加构建后事件,以将一些非托管的第 3 方程序集复制到其 $(TargetDir) 中,但我必须添加此构建后事件将这些项目一一事件化,这不是我想要的。所以我想知道是否有一种方法可以解决这个问题,而不必为大多数项目一一添加事件。
最佳答案
Add build event to multiple projects without adding one by one
您可以将复制目标添加到Directory.Build.props
文件中,并在解决方案目录中设置此.props
。如果 props 文件名为 Directory.Build.props
,它将自动导入到目录层次结构中的所有项目中。
在我的Directory.Build.props
下面:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="CopySAssembly" AfterTargets="Build">
<Message Text="YourCopyTask"></Message>
</Target>
</Project>
或者,您可以使用 nuget 包来管理那些非托管的第 3 方程序集,将此 nuget 包添加到多个项目中应该非常容易,使用 nuget 包管理器来解决:
Create nuget package from dlls
希望这有帮助。
关于visual-studio - 为多个项目添加构建事件,无需一一添加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49136878/