【发布时间】:2021-02-13 13:46:39
【问题描述】:
我使用 vcpkg 作为 Visual Studio C++ 项目的包管理器。我已经创建了初始目标来基本设置 vcpkg(克隆 vcpkg 存储库并下载 vcpkg.exe):
<Target Name="EnsureVcpkgBuild" BeforeTargets="PrepareForBuild">
<Exec Command="git clone $(VcpkgRepo).git ..\packages\vcpkg" Condition="!Exists('..\packages\vcpkg\.git')" ContinueOnError="true" />
<Exec Command="git --git-dir=..\packages\vcpkg\.git --work-tree=..\packages\vcpkg pull --ff-only" Condition="Exists('..\packages\vcpkg\.git')" ContinueOnError="true" />
<Exec Command="..\packages\vcpkg\bootstrap-vcpkg.bat" Condition="!Exists('..\packages\vcpkg\vcpkg.exe')" ContinueOnError="true" />
<PropertyGroup>
<ErrorText>This project uses vcpkg that is missing on this computer. Manually download from $(VcpkgRepo) and place the contents in {0}. Or install git and add it to your path, for more information see https://git-scm.com. The missing file is {1}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\vcpkg\vcpkg.exe')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\vcpkg\', '..\packages\vcpkg\vcpkg.exe'))" />
<Error Condition="!Exists('..\packages\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\vcpkg\', '..\packages\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets'))" />
</Target>
在我的项目中,我正在导入 vcpkg 目标文件:
<ImportGroup>
<Import Project="..\packages\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets" Condition="Exists('..\packages\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets')" />
</ImportGroup>
此设置可确保在 Visual Studio 中顺利构建,无需任何额外工作。但是,在使用 CI/CD 管道时,我必须先调用EnsureVcpkgBuild,然后再尝试构建项目。我能否以不必调用 EnsureVcpkgBuild 并启动构建自动设置 vcpkg 并导入 vcpkg.targets 的方式设置此项目?
【问题讨论】:
标签: c++ windows visual-studio msbuild vcpkg