我有 n 个 csharp 项目和 cpp 项目的解决方案,这个 cpp 提供接口和头文件,因此这些 csharp 可以在其他 cpp 解决方案中使用。
构建机器配置为使用任何 CPU 架构构建 csharp 项目,因此它在 Solution\bin\Release 中为每个构建提供单个程序集。对于 cpp,anyCpu 不可用,因此我构建了两次项目并将程序集存储在 Solution\bin\Release\x86 和 x64 文件夹中。
这一切都是为了将它作为带有 .targets 文件的单个包打包在 nuget 中,以方便在其他 cpp 项目中使用。
问题是 cpp 项目正在使用 ResolveAssemblyReference 寻找 csharp 组件并且找不到它,从而给出误导性消息:
ResolveAssemblyReferences:
Primary reference "Implementation".
Could not find dependent files. Expected file "C:\Jenkins\Workspace\Solution\bin\Release\x86\Implementation.dll" does not exist.
Could not find dependent files. Expected file "C:\Jenkins\Workspace\Solution\bin\Release\x86\Implementation.dll" does not exist.
Resolved file path is "C:\Jenkins\Workspace\Solution\bin\Release\x86\Implementation.dll".
Reference found at search path location "".
我尝试使用命令行属性、自定义目标/属性来替代 ResolveAssemblyReferences 行为,但没有任何运气。https://docs.microsoft.com/en-us/visualstudio/msbuild/resolveassemblyreference-task?view=vs-2017中描述的参数似乎是在构建过程中计算的,我无法注入任何值,应该在这种情况类似于 $(OutDir)..
一个可行的解决方案似乎是将 c# dll 复制到每个 cpp 文件夹中,但我认为这不是正确解决它的方法。
我得到的关闭是使用 /p:ReferencePath 如下所示:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MsBuild\15.0\bin\MsBuild.exe" /p:BuildProjectReferences=false /p:Configuration=Release /p:DebugType=full /p:DebugSymbols =true /p:PlatformToolset=v120 /p:WindowsTargetPlatformVersion=8.1 /p:ForceImportBeforeCppTargets="C:\Jenkins\Workspace\Solution\Cpp.props" /p:OutDir="C:\Jenkins\Workspace\Solution\bin\ Release\x86\" /p:Platform=Win32 /t:Build Interface\Interface.vcxproj /p:ReferencePath="C:\jenkins\workspace\Solution\bin\Release"
我的自定义 Cpp.props 可以:
<Target Name="Output" BeforeTargets="ResolveAssemblyReferences">
<Message Text="AssemblySearchPaths: $(AssemblySearchPaths)" />
</Target>
并通过添加 /p:ReferencePath 它作为第二条记录添加到 AssemblySearchPaths 中,在 {CandidateAssemblyFiles}; 之后 但它仍然没有找到那些 dll