build - msbuild 不会将引用的 native 项目的输出复制到 c# 项目输出目录

标签 build msbuild visual-studio-2017 devenv

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

设置:

  • c#项目
  • c++项目
  • c# 项目有一个对 c++ 项目的引用,包含以下几行:
    <ProjectReference Include="projectB.vcxproj">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
        <OutputItemType>Content</OutputItemType>
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </ProjectReference>
    

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

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

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

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

    最佳答案

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

    当前的解决方案,这似乎工作是添加:<Targets>Build;BuiltProjectOutputGroup</Targets>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 , 在注释 Build referenced projects when building from the command line. 前面的 MSBuild 任务中- 成功了。

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

    更新 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下面一行引起了我的注意:
    <Output TaskParameter="TargetOutputs" ItemName="_ResolvedProjectReferencePaths" Condition="'%(_MSBuildProjectReferenceExistent.ReferenceOutputAssembly)'=='true' or '$(DesignTimeBuild)' == 'true'"/>
    我知道在visual-studio里面有这个工作。谷歌搜索让我到 https://github.com/Microsoft/msbuild/wiki/MSBuild-Tips-&-Tricks .
    从那里开始添加 /p:DesignTimeBuild=true 的路径很短到 msbuild 命令行。

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

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

    欢迎任何其他建议。

    关于build - msbuild 不会将引用的 native 项目的输出复制到 c# 项目输出目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47960519/

    相关文章:

    c++ - 无法从命令行 VS2017 为 C++ 运行 msbuild

    asp.net-core - Visual Studio 15 上不存在 ASP.NET Core Web 应用程序模板

    c - C语言的sublime text 2构建系统

    ios - 从新项目更新 iOS 应用程序

    c# - 修改 .NET 项目文件和引用属性

    .net - 如何在 csproj 中使用 dotnet-pack --version-suffix?

    c++ - 调试 :FASTLINK - What is this error?

    asp.net-core - 解决方案资源管理器中的包选项是什么?

    ios - Swift 项目需要很长时间才能构建。我能做些什么?

    java - 如何避免gradle中的字母数字执行顺序