|
12 | 12 | <!-- Include custom MSBuild targets/tasks --> |
13 | 13 | <Import Project="$(MSBuildThisFileDirectory)GVFS\GVFS.MSBuild\GVFS.targets" /> |
14 | 14 |
|
| 15 | + <!-- |
| 16 | + Auto-restore vcpkg native dependencies when missing. |
| 17 | + Modeled after vcpkg's official VcpkgInstallManifestDependencies target |
| 18 | + (scripts/buildsystems/msbuild/vcpkg.targets), adapted for .csproj projects |
| 19 | + and dual-triplet installs (static-aot + dynamic). |
| 20 | +
|
| 21 | + Key differences from official vcpkg.targets: |
| 22 | + - Hooks PrepareForBuild instead of ClCompile (which doesn't exist in csproj) |
| 23 | + - Installs two triplets (static for AOT linking, dynamic for runtime P/Invoke) |
| 24 | + - Outputs to out/vcpkg_installed/ instead of src/vcpkg_installed/ |
| 25 | + - Discovers vcpkg via VCPKG_INSTALLATION_ROOT, VS-bundled path, or PATH |
| 26 | +
|
| 27 | + Stamp file pattern: the target uses Inputs/Outputs so MSBuild skips it entirely |
| 28 | + when the manifests haven't changed and the stamp file is up-to-date. |
| 29 | + Build.bat also runs vcpkg install upfront, making this a no-op for CLI builds. |
| 30 | + --> |
| 31 | + <PropertyGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'"> |
| 32 | + <_VcpkgManifestFile>$(RepoSrcPath)vcpkg.json</_VcpkgManifestFile> |
| 33 | + <_VcpkgConfigFile>$(RepoSrcPath)vcpkg-configuration.json</_VcpkgConfigFile> |
| 34 | + <_VcpkgStampFile>$(RepoOutPath)vcpkg_installed\.msbuildstamp</_VcpkgStampFile> |
| 35 | + </PropertyGroup> |
| 36 | + |
| 37 | + <ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'"> |
| 38 | + <_VcpkgManifestInputs Include="$(_VcpkgManifestFile)" /> |
| 39 | + <_VcpkgManifestInputs Include="$(_VcpkgConfigFile)" Condition="Exists('$(_VcpkgConfigFile)')" /> |
| 40 | + </ItemGroup> |
| 41 | + |
| 42 | + <Target Name="_RestoreVcpkgDependencies" |
| 43 | + BeforeTargets="PrepareForBuild;ComputeFilesToPublish" |
| 44 | + Condition="'$(MSBuildProjectName)' == 'GVFS.Common'" |
| 45 | + Inputs="@(_VcpkgManifestInputs)" |
| 46 | + Outputs="$(_VcpkgStampFile)"> |
| 47 | + |
| 48 | + <!-- Locate vcpkg: VCPKG_INSTALLATION_ROOT > VS-bundled > PATH --> |
| 49 | + <PropertyGroup> |
| 50 | + <_VcpkgExe Condition="Exists('$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe')">$(VCPKG_INSTALLATION_ROOT)\vcpkg.exe</_VcpkgExe> |
| 51 | + <_VcpkgExe Condition="'$(_VcpkgExe)' == '' and Exists('$(VsInstallRoot)\VC\vcpkg\vcpkg.exe')">$(VsInstallRoot)\VC\vcpkg\vcpkg.exe</_VcpkgExe> |
| 52 | + <_VcpkgManifestArg>--x-manifest-root="$(RepoSrcPath.TrimEnd('\'))"</_VcpkgManifestArg> |
| 53 | + </PropertyGroup> |
| 54 | + |
| 55 | + <!-- For dotnet build (no VsInstallRoot): find VS-bundled vcpkg via vswhere --> |
| 56 | + <Exec Command=""$(MSBuildProgramFiles32)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -property installationPath" |
| 57 | + ConsoleToMSBuild="true" IgnoreExitCode="true" StandardOutputImportance="low" |
| 58 | + Condition="'$(_VcpkgExe)' == ''"> |
| 59 | + <Output TaskParameter="ConsoleOutput" PropertyName="_VsInstallPath" /> |
| 60 | + </Exec> |
| 61 | + <PropertyGroup Condition="'$(_VcpkgExe)' == '' and '$(_VsInstallPath)' != '' and Exists('$(_VsInstallPath)\VC\vcpkg\vcpkg.exe')"> |
| 62 | + <_VcpkgExe>$(_VsInstallPath)\VC\vcpkg\vcpkg.exe</_VcpkgExe> |
| 63 | + </PropertyGroup> |
| 64 | + |
| 65 | + <!-- Final fallback: bare vcpkg on PATH --> |
| 66 | + <PropertyGroup Condition="'$(_VcpkgExe)' == ''"> |
| 67 | + <_VcpkgExe>vcpkg</_VcpkgExe> |
| 68 | + </PropertyGroup> |
| 69 | + |
| 70 | + <Message Importance="high" Text="[vcpkg] Installing native dependencies to $(RepoOutPath)vcpkg_installed\" /> |
| 71 | + |
| 72 | + <MakeDir Directories="$(RepoOutPath)vcpkg_installed\" /> |
| 73 | + <Exec Command=""$(_VcpkgExe)" install --x-wait-for-lock --triplet x64-windows-static-aot --x-install-root="$(RepoOutPath)vcpkg_installed\static" $(_VcpkgManifestArg)" |
| 74 | + StandardOutputImportance="High" StandardErrorImportance="High" /> |
| 75 | + <Exec Command=""$(_VcpkgExe)" install --x-wait-for-lock --triplet x64-windows-dynamic --x-install-root="$(RepoOutPath)vcpkg_installed\dynamic" $(_VcpkgManifestArg)" |
| 76 | + StandardOutputImportance="High" StandardErrorImportance="High" /> |
| 77 | + |
| 78 | + <Error Condition="!Exists('$(RepoOutPath)vcpkg_installed\dynamic\x64-windows-dynamic\bin\git2.dll')" |
| 79 | + Text="vcpkg install completed but expected output files are missing. Check vcpkg output above for errors." /> |
| 80 | + |
| 81 | + <Touch Files="$(_VcpkgStampFile)" AlwaysCreate="true" /> |
| 82 | + </Target> |
| 83 | + |
15 | 84 | <!-- |
16 | 85 | Copy native C++ hook executables and managed peer executables to GVFS.exe |
17 | 86 | output directory. In a production install all binaries are co-located in one |
|
0 commit comments