在Build Events中使用另一个项目的变量

时间:2015-04-20 18:58:03

标签: visual-studio-2013

我有一个包含多个项目的解决方案。我可以在Build Events中使用项目变量,例如$(TargetDir)来访问当前项目的路径和文件。

  • 解决方案'MyApp'
    • MyApp的
    • MyApp.Core
    • MyApp.Setup

我想在MyApp.Setup中添加Pre-Build-Event。 $(TargetDir)将返回D:\MyApp\MyApp.Setup\bin\Debug,但我想从MyApp-Output Directory收集所有文件并将它们放入安装目录。

那么是否可以在构建事件中从其他项目访问变量?

类似的东西:

copy "$(MyApp.TargetDir)\*.*" "$(ProjectDir)\externals"

1 个答案:

答案 0 :(得分:-1)

我建议您将所有解决方案项目构建到一个文件夹中,并在该文件夹中创建特定的项目子文件夹。目前,您的项目的TargetDir变量值为:

MyApp         - D:\MyApp\MyApp\bin\Debug
MyApp.Core    - D:\MyApp\MyApp.Core\bin\Debug
MyApp.Setup   - D:\MyApp\MyApp.Setup\bin\Debug

但您可以创建公共目标目录,因此TargetDir值:

MyApp         - D:\MyApp\Debug\MyApp\bin
MyApp.Core    - D:\MyApp\Debug\MyApp.Core\bin
MyApp.Setup   - D:\MyApp\Debug\MyApp.Setup\bin

在Pre-Build-Event中你可以参考它:

copy "$(TargetDir)\..\MyApp\*.*" "$(ProjectDir)\externals"