Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSBuild] vcpkg not respecting Visual Studio project properties #27906

Closed
nikitalita opened this issue Nov 19, 2022 · 6 comments
Closed

[MSBuild] vcpkg not respecting Visual Studio project properties #27906

nikitalita opened this issue Nov 19, 2022 · 6 comments
Assignees
Labels
category:question This issue is a question

Comments

@nikitalita
Copy link

nikitalita commented Nov 19, 2022

Describe the bug
vcpkg does not respect project properties set in Visual Studio 2022. This seems to be because they are already overridden before they are inherited.

As near as I can figure out, this only affects certain projects, and it seems to be a limitation of current MSBuilds; Property groups in vcpkg.targets are sometimes evaluated before the project configuration properties are inherited for the build target. I think you may have to create a task to create these overrides instead of doing them in root.

Edit: I figured out the conditions where this happens, see below: #27906 (comment)

This is a huge problem for manifest builds, because if we are in manifest mode, we should install the packages to $(VcpkgManifestRoot)\vcpkg_installed by default, but since we don't read the properties before _ZVcpkgInstalledDir is overridden, we install to $(VcpkgRoot)\installed. You can't fix it by setting VcpkgInstalledDir, because that only gets read into _ZVcpkgInstalledDir if it's not set, and it's already set by the time the project properties are inherited.

You can test this yourself by putting the following in vcpkg.targets:

  <Target Name="Output build properties" BeforeTargets="VcpkgInstallManifestDependencies">
    <Message Text="VcpkgRoot is '$(VcpkgRoot)' (default is derived from a function)"
    Importance="High" />
    <Message Text="_ZVcpkgRoot is '$(_ZVcpkgRoot)'"
    Importance="High" />

    <Message Text="VcpkgManifestRoot is '$(VcpkgManifestRoot)' (default is derived from a function)"
    Importance="High" />
    <Message Text="_ZVcpkgManifestRoot is '$(_ZVcpkgManifestRoot)'"
    Importance="High" />

    <Message Text="VcpkgEnableManifest is '$(VcpkgEnableManifest)'"
    Importance="High" />
    <Message Text="VcpkgInstalledDir is '$(VcpkgInstalledDir)'"
    Importance="High" />
    <Message Text="_ZVcpkgInstalledDir is '$(_ZVcpkgInstalledDir)' (If VcpkgInstalledDir is blank and we're in manifest, this should default to $(VcpkgManifestRoot)/vcpkg_installed)"
    Importance="High" />

    <Message Text="VcpkgUseStatic is '$(VcpkgUseStatic)'"
    Importance="High" />
    <Message Text="_ZVcpkgLinkage is '$(_ZVcpkgLinkage)' (If UseStatic is set, this should be '-static'"
    Importance="High" />
  
    <Message Text="VcpkgConfiguration is '$(VcpkgConfiguration)' "
    Importance="High" />
    <Message Text="_ZVcpkgNormalizedConfiguration is '$(_ZVcpkgNormalizedConfiguration)'"
    Importance="High" />

    <Message Text="VcpkgPlatformTarget is '$(VcpkgPlatformTarget)'"
    Importance="High" />
    <Message Text="VcpkgOSTarget is '$(VcpkgOSTarget)'"
    Importance="High" />
    <Message Text="_ZVcpkgHostTripletSuffix is '$(_ZVcpkgHostTripletSuffix)'"
    Importance="High" />
    <Message Text="_ZVcpkgHostTripletParameter is '$(_ZVcpkgHostTripletParameter)'"
    Importance="High" />

  </Target>

Environment

  • OS: Windows
  • Compiler: Visual Studio 17.4.1

To Reproduce
Steps to reproduce the behavior:

  1. vgpkg integrate install
  2. Override default settings in VS 2022 project config
  3. Observe that settings are not respected

Failure logs
Example config:
image
Example logs:

Build started...
1>------ Build started: Project: DarkId.Papyrus.DebugServer.Skyrim, Configuration: Debug x64 ------
1>VcpkgRoot is 'C:\tools\vcpkg' (default is derived from a function)
1>_ZVcpkgRoot is 'C:\tools\vcpkg\'
1>VcpkgManifestRoot is 'C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server' (default is derived from a function)
1>_ZVcpkgManifestRoot is 'C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\'
1>VcpkgEnableManifest is 'true'
1>VcpkgInstalledDir is 'C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\some_test_dir'
1>_ZVcpkgInstalledDir is 'C:\tools\vcpkg\installed\' (If VcpkgInstalledDir is blank and we're in manifest, this should default to C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server/vcpkg_installed)
1>VcpkgUseStatic is 'true'
1>_ZVcpkgLinkage is '' (If UseStatic is set, this should be '-static'
1>VcpkgConfiguration is 'Debug'
1>_ZVcpkgNormalizedConfiguration is 'Release'
1>VcpkgPlatformTarget is 'x64'
1>VcpkgOSTarget is 'windows'
1>_ZVcpkgHostTripletSuffix is ''
1>_ZVcpkgHostTripletParameter is ''
1>Installing vcpkg dependencies to C:\tools\vcpkg\installed\
1>"C:\tools\vcpkg\vcpkg.exe" install  --x-wait-for-lock --triplet "x64-windows" --vcpkg-root "C:\tools\vcpkg\\" "--x-manifest-root=C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\\" "--x-install-root=C:\tools\vcpkg\installed\\"
1>Detecting compiler hash for triplet x64-windows...
1>The following packages will be built and installed:
1>  * boost-algorithm[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-algorithm\bb8f387ba19a3fabe9d59398185263b6448ad028
1>  * boost-asio[core]:x64-windows -> 1.80.0#2 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-asio\95a00e0e4990c9e8179a705132ce53e5f928bbb6
1>  * boost-chrono[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-chrono\ea2397905d6361f15dca29c4d550d0030fc513af
1>  * boost-container[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-container\669c74604cc73bada702b35c5ae597428adb02d9
1>  * boost-context[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-context\6acc7fc6639406a0ec333c52403b20ac6fcd5aab
1>  * boost-coroutine[core]:x64-windows -> 1.80.0#2 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-coroutine\8ad73dc1827cbca291002b28510f60912cbf12e8
1>  * boost-date-time[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-date-time\0dcad93c43fe52b123c5e3abf8c3e94112ebe4f0
1>  * boost-exception[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-exception\bd131b74e6a6bf14aaf31aef22be644b4fa57a3a
1>  * boost-lexical-cast[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-lexical-cast\2f68712a48e0aefc65866fe43edc152e1afd5e94
1>  * boost-modular-build-helper[core]:x64-windows -> 1.80.0#3 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-modular-build-helper\4a8c162e2661795b998a8435b6ec7207608fe73a
1>  * boost-range[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-range\7436352f0a4c6248fc5ddd3dbdf54cf745ae39e3
1>  * boost-regex[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-regex\9988f582a655bfd7d3d88dbaa771ec575784a750
1>  * boost-system[core]:x64-windows -> 1.80.0#1 -- C:\tools\vcpkg\buildtrees\versioning_\versions\boost-system\9a6e70bad5ea38a9e78b3068ce0bc9237d4ad413
1>    commonlibsse-ng[core]:x64-windows -> 3.5.6 -- C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\../vcpkg-colorglass/ports\commonlibsse-ng
1>    eventpp[core]:x64-windows -> 0.1.2 -- C:\tools\vcpkg\buildtrees\versioning_\versions\eventpp\3f11cacc8b5a6f9f2951992d29cee39e52ef601f
1>    f4se[core,plugin,scripts]:x64-windows -> 0.6.23 -- C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\../vcpkg-colorglass/ports\f4se
1>    nlohmann-json[core]:x64-windows -> 3.7.0 -- C:\tools\vcpkg\buildtrees\versioning_\versions\nlohmann-json\09087343e4426668b9293613aab3e807691b7cd7
1>    openssl[core]:x64-windows -> 1.0.2o-3 -- C:\tools\vcpkg\buildtrees\versioning_\versions\openssl\39d1773390a9817dd776d1d90e809d873437daa7
1>  * script-extender-common[core]:x64-windows -> 2.1.5 -- C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\../vcpkg-colorglass/ports\script-extender-common
1>    skse[core,plugin,scripts]:x64-windows -> 2.2.3 -- C:\Users\Nikita\Workspace\skyrim-mod-workspace\papyrus-debug-server\../vcpkg-colorglass/ports\skse
1>  * vcpkg-cmake-get-vars[core]:x64-windows -> 2022-09-04 -- C:\tools\vcpkg\buildtrees\versioning_\versions\vcpkg-cmake-get-vars\898079c6021ced406d7c75f852e67a5e8861db9b
1>    websocketpp[core]:x64-windows -> 0.8.2 -- C:\tools\vcpkg\buildtrees\versioning_\versions\websocketpp\c717c6c7fe929ef1c9cc7b2250e78700326940c4
1>  * zlib[core]:x64-windows -> 1.2.13 -- C:\tools\vcpkg\buildtrees\versioning_\versions\zlib\ad5a49006f73b45b715299515f31164131b51982
1>Additional packages (*) will be modified to complete this operation.
1>Restored 3 package(s) from C:\Users\Nikita\AppData\Local\vcpkg\archives in 7.604 s. Use --debug to see more details.
1>Installing 1/23 commonlibsse-ng:x64-windows...
[...]
========== Elapsed 00:11.821 ==========
@nikitalita
Copy link
Author

May be related to these:
#19767
#18906

@nikitalita
Copy link
Author

nikitalita commented Nov 19, 2022

I can't reproduce this on a simple example. Here's the project that I'm experiencing this on: https://github.com/nikitalita/papyrus-debug-server/tree/wip-modernize

This is not a simple project configuration; the vcpkg.json and solution are in the root, and the main projects point to the same codebase, but with different DEFINES set for different pragmas. This might be why vcpkg.targets is having its properties evaluated before the project properties are inherited?

@nikitalita
Copy link
Author

nikitalita commented Nov 19, 2022

I figured it out the conditions that this happens under. The issue is that Visual Studio 2022 will sometimes add the PropertyGroups containing the vcpkg properties AFTER <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />. Moving those PropertyGroups before that makes it behave as expected.

Visual Studio seems to add PropertyGroups after the last PropertyGroup in the project file, and there was one in mine that was located after the targets import. Either way, I am not sure that anything can be done here on vcpkg's end; this sounds like a bug in Visual Studio or MSBuild.

nikitalita added a commit to nikitalita/papyrus-debug-server that referenced this issue Nov 19, 2022
@FrankXie05 FrankXie05 self-assigned this Nov 21, 2022
@FrankXie05
Copy link
Contributor

FrankXie05 commented Nov 21, 2022

@nikitalita Thank you for submitting the issue. For VS integration, vcpkg provides these two files : vcpkg.props and vcpkg.targets to preset some parameters. You can reload the configuration file by modifying the C:\Users\xxx\AppData\Local\vcpkg\vcpkg.user.props.
But it may not meet all the requirements, which is the result of the design. Maybe you can submit a feedback to vs. :)

@FrankXie05 FrankXie05 added the category:question This issue is a question label Nov 21, 2022
@FrankXie05
Copy link
Contributor

We hope your question was answered to your satisfaction; if it wasn't, you can reopen with more info.

@FrankXie05 FrankXie05 closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2022
nikitalita added a commit to nikitalita/papyrus-debug-server that referenced this issue Dec 24, 2022
@MikeMarcin
Copy link

I figured it out the conditions that this happens under. The issue is that Visual Studio 2022 will sometimes add the PropertyGroups containing the vcpkg properties AFTER <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />. Moving those PropertyGroups before that makes it behave as expected.

FWIW I ran into this issue today adding vcpkg in manifest mode to an existing large project and, after much searching and pulling out most of my hair, this was the only fix that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:question This issue is a question
Projects
None yet
Development

No branches or pull requests

3 participants