【问题标题】:msbuild doesn't copy output of referenced native project to c# project out dirmsbuild 不会将引用的本机项目的输出复制到 c# project out dir
【发布时间】:2018-06-06 05:30:55
【问题描述】:

我已经为此苦苦挣扎了很长时间。

设置:

  • c# 项目
  • c++ 项目
  • c# 项目具有对 c++ 项目的引用,其中包含以下几行:

    <ProjectReference Include="projectB.vcxproj">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
        <OutputItemType>Content</OutputItemType>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </ProjectReference>
    

这适用于视觉工作室。 这在从命令行使用 devenv 时有效。 从命令行使用 msbuild 时 - c++ 项目的输出文件不会复制到 c# 项目的输出目录中。

我无法使用 msbuild 解决这个问题。读了很多关于它,没有任何工作。尝试使用 diag 详细程度进行调试 - 但 msbuild 和 visual-studio 的日志非常不同...... 我无法使用 devenv,因为构建机器没有有效的视觉工作室。

在带有诊断详细信息的 msbuild 日志中,我看到: Target "GetCopyToOutputDirectoryItems" skipped. Previously built successfully. 这是视觉工作室日志中的位置 - 它看起来不同 - 实际上用于将引用的本机文件复制到 c# 输出目录。 也许与构建顺序有关?..

在 msbuild 日志中 - 我还看到: Target "_CopyOutOfDateSourceItemsToOutputDirectoryAlways" skipped, due to false condition; ( '@(_SourceItemsToCopyToOutputDirectoryAlways)' != '' ) was evaluated as ( '' != '' ). 在visual-studio构建日志中,我看到这个目标被执行(它在GetCopyToOutputDirectoryItems目标之后)

【问题讨论】:

    标签: build msbuild visual-studio-2017 devenv


    【解决方案1】:

    更新 3: 似乎以前的解决方案会导致不必要的副作用,例如在运行多线程构建时破坏构建。

    目前似乎可行的解决方案是添加: &lt;Targets&gt;Build;BuiltProjectOutputGroup&lt;/Targets&gt;ProjectReference 部分。

    更新 2:

    变化:

    Targets="%(_MSBuildProjectReferenceExistent.Targets)"

    Targets="%(_MSBuildProjectReferenceExistent.Targets);GetTargetPath"

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets 中,在 MSBuild 任务中,前面有注释 Build referenced projects when building from the command line. - 成功了。

    但是,我对这个解决方案没有信心,因为我不了解整个构建过程。这只是猜测。

    更新 1:

    使用/p:DesignTimeBuild=true 会影响依赖构建顺序。不能工作。继续调查...

    可能的解决方案 1:

    C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets发了很多消息后

    我终于明白了: QUIRKING FOR DEV10

    我仍然不确定这是怎么回事,而且我看到开发人员计划消除这个怪癖(请参阅https://github.com/Microsoft/msbuild/issues/1890)。

    突然DesignTimeBuild在下面一行引起了我的注意:

    &lt;Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths" Condition="'%(_MSBuildProjectReferenceExistent.ReferenceOutputAssembly)'=='true' or '$(DesignTimeBuild)' == 'true'"/&gt;

    我知道在visual-studio里面这个工作。谷歌搜索让我找到https://github.com/Microsoft/msbuild/wiki/MSBuild-Tips-&-Tricks。 从那里开始,将/p:DesignTimeBuild=true 添加到 msbuild 命令行的路径很短。

    这使它起作用了。引用的程序集已被复制。

    我认为这不应该是解决方案,但它有效,并且似乎没有破坏其他任何东西(目前)。

    欢迎提出任何其他建议。

    【讨论】:

    • BuiltProjectOutputGroup目标的任何文档吗?
    猜你喜欢
    • 2010-09-20
    • 2014-10-10
    • 2012-06-26
    • 2011-08-20
    • 2012-05-17
    • 1970-01-01
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    相关资源
    最近更新 更多