我为此苦苦挣扎了很长时间。
设置:
<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/