msbuild 不会将引用的本机项目的输出复制到 c# project out dir
msbuild doesn't copy output of referenced native project to c# project out dir
我为此苦恼了很长时间。
设置:
- c# 项目
- c++ 项目
c# 项目有一个 c++ 项目的引用,其中包含以下行:
<ProjectReference Include="projectB.vcxproj">
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
<OutputItemType>Content</OutputItemType>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</ProjectReference>
这适用于 visual-studio。
这在从命令行使用 devenv 时有效。
从命令行使用 msbuild 时 - c++ 项目的输出文件不会复制到 c# 项目的输出目录中。
我无法使用 msbuild 修复该问题。阅读了很多有关它的信息,但没有任何效果。尝试使用 diag verbosity 进行调试 - 但 msbuild 和 visual-studio 的日志非常不同......
我无法转而使用 devenv,因为构建机器没有有效的 visual-studio。
在带有详细诊断信息的 msbuild 日志中,我看到:
Target "GetCopyToOutputDirectoryItems" skipped. Previously built successfully.
这是 visual-studio 日志中的位置 - 它看起来不同 - 实际上用于将引用的本机文件复制到 c# 输出目录。
也许与构建顺序有关?..
在 msbuild 日志中 - 我还看到:
Target "_CopyOutOfDateSourceItemsToOutputDirectoryAlways" skipped, due to false condition; ( '@(_SourceItemsToCopyToOutputDirectoryAlways)' != '' ) was evaluated as ( '' != '' ).
在 visual-studio 构建日志中,我看到此目标已执行(它紧跟在 GetCopyToOutputDirectoryItems 目标之后)
更新 3:
似乎以前的解决方案会导致不必要的副作用,例如在 运行 多线程构建时破坏构建。
目前看来确实有效的解决方案是添加:
<Targets>Build;BuiltProjectOutputGroup</Targets>
到 ProjectReference
部分。
更新二:
变化中:
Targets="%(_MSBuildProjectReferenceExistent.Targets)"
至
Targets="%(_MSBuildProjectReferenceExistent.Targets);GetTargetPath"
在 C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
中,在注释 Build referenced projects when building from the command line.
前面的 MSBuild 任务中 - 成功了。
但是,我对这个解决方案没有信心,因为我不了解整个构建过程。这只是一个猜测。
更新 1:
使用 /p:DesignTimeBuild=true
会影响依赖构建顺序。不能工作。继续调查...
可能方案一:
将大量消息放入C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.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 命令行的路径很短。
这让它起作用了。引用的程序集已复制过来。
我不认为这应该是解决方案,但它有效,而且似乎没有破坏任何其他东西(还)。
欢迎提出任何其他建议。
我为此苦恼了很长时间。
设置:
- c# 项目
- c++ 项目
c# 项目有一个 c++ 项目的引用,其中包含以下行:
<ProjectReference Include="projectB.vcxproj"> <ReferenceOutputAssembly>false</ReferenceOutputAssembly> <OutputItemType>Content</OutputItemType> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </ProjectReference>
这适用于 visual-studio。 这在从命令行使用 devenv 时有效。 从命令行使用 msbuild 时 - c++ 项目的输出文件不会复制到 c# 项目的输出目录中。
我无法使用 msbuild 修复该问题。阅读了很多有关它的信息,但没有任何效果。尝试使用 diag verbosity 进行调试 - 但 msbuild 和 visual-studio 的日志非常不同...... 我无法转而使用 devenv,因为构建机器没有有效的 visual-studio。
在带有详细诊断信息的 msbuild 日志中,我看到:
Target "GetCopyToOutputDirectoryItems" skipped. Previously built successfully.
这是 visual-studio 日志中的位置 - 它看起来不同 - 实际上用于将引用的本机文件复制到 c# 输出目录。
也许与构建顺序有关?..
在 msbuild 日志中 - 我还看到:
Target "_CopyOutOfDateSourceItemsToOutputDirectoryAlways" skipped, due to false condition; ( '@(_SourceItemsToCopyToOutputDirectoryAlways)' != '' ) was evaluated as ( '' != '' ).
在 visual-studio 构建日志中,我看到此目标已执行(它紧跟在 GetCopyToOutputDirectoryItems 目标之后)
更新 3: 似乎以前的解决方案会导致不必要的副作用,例如在 运行 多线程构建时破坏构建。
目前看来确实有效的解决方案是添加:
<Targets>Build;BuiltProjectOutputGroup</Targets>
到 ProjectReference
部分。
更新二:
变化中:
Targets="%(_MSBuildProjectReferenceExistent.Targets)"
至
Targets="%(_MSBuildProjectReferenceExistent.Targets);GetTargetPath"
在 C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\Microsoft.Common.CurrentVersion.targets
中,在注释 Build referenced projects when building from the command line.
前面的 MSBuild 任务中 - 成功了。
但是,我对这个解决方案没有信心,因为我不了解整个构建过程。这只是一个猜测。
更新 1:
使用 /p:DesignTimeBuild=true
会影响依赖构建顺序。不能工作。继续调查...
可能方案一:
将大量消息放入C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.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 命令行的路径很短。
这让它起作用了。引用的程序集已复制过来。
我不认为这应该是解决方案,但它有效,而且似乎没有破坏任何其他东西(还)。
欢迎提出任何其他建议。