我有时通过 P/Invoke 将原生 C++(不是 C++/CLI 或 C++/CX,只是 C++)和 C# 项目结合起来。
我曾经使用过这样的配置:
$(ProjectName)_d
仅在调试配置上。 $(SolutionDir)Release\ProjA.dll
和 $(SolutionDir)Debug\ProjA_d.dll
将被制作。 dllName
的 DllImport
通过使用 #if DEBUG
. ProjA.dll
和 ProjA_d.dll
(和 *.pdb
)到 ProjB 作为链接。 然后一切都很顺利。 ProjB 检测 ProjA 中的变化。
但是,在 Azure DevOps 中,它无法构建,因为
ProjA_d.dll
不是在发布版本中创建的(需要第 3 步。)如果存在,我想告诉常见的方法。还是我必须编写构建事件并制作虚拟文件?
最佳答案
您可以在构建管道中添加三个构建任务,并为每个构建任务配置正确的项目路径和配置,一个使用调试配置构建 c++ 项目,一个使用发布配置构建,另一个构建 c#。请引用下面的截图。
根据需要配置每个构建任务。 将项目指向您要构建的特定项目的路径 .请引用下面的例子。
解决方案
# set env and vars
- task: MSBuild@1
inputs:
solution: 'ProjA1/ProjA1.vcxproj'
platform: '$(buildPlatform)'
configuration: 'Debug'
- task: MSBuild@1
inputs:
solution: 'ProjA1/ProjA1.vcxproj'
platform: '$(buildPlatform)'
configuration: 'Release'
- task: CmdLine@2
inputs:
script: |
xcopy /I /E /Y ProjA1\Debug Debug
xcopy /I /E /Y ProjA1\Release Release
- task: MSBuild@1
inputs:
solution: 'ProjA2/ProjA2.vcxproj'
platform: '$(buildPlatform)'
configuration: 'Debug'
- task: MSBuild@1
inputs:
solution: 'ProjA2/ProjA2.vcxproj'
platform: '$(buildPlatform)'
configuration: 'Release'
- task: CmdLine@2
inputs:
script: |
xcopy /I /E /Y ProjA2\Debug Debug
xcopy /I /E /Y ProjA2\Release Release
- task: VSBuild@1
inputs:
solution: '$(solution)'
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
# tests
关于c# - 结合适用于本地和 Azure DevOps 的 C++ 和 C# 项目的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59367031/