microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.63k stars 6.25k forks source link

vcpkg included with VS 2022 could not locate a complete Visual Studio instance #32857

Open kylecmarshall opened 1 year ago

kylecmarshall commented 1 year ago

Describe the bug VS 2022 Community doesn't work with the included vcpkg. Both the included vcpkg and any release of vcpkg I tried could not locate Visual Studio.

Environment

To Reproduce Steps to reproduce the behavior:

  1. Install VS 2022 Community with C++ Desktop and Gaming options
  2. Create new project
  3. Add vcpkg.json in solution directory with directxtk as the only dependency (any dependency will cause an error)
  4. Build project in VS

Expected behavior Successful build of directxtk and the project

Failure logs

Build started...
1>------ Build started: Project: hexatron_viz, Configuration: Debug x64 ------
1>Installing vcpkg dependencies to C:\Users\kmarshal\source\repos\hexatron_viz\vcpkg_installed\x64-windows\
1>"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\vcpkg.exe" install  --x-wait-for-lock --triplet "x64-windows" --vcpkg-root "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\\" "--x-manifest-root=C:\Users\kmarshal\source\repos\hexatron_viz\\" "--x-install-root=C:\Users\kmarshal\source\repos\hexatron_viz\vcpkg_installed\x64-windows\\"
1>Fetching registry information from https://github.com/microsoft/vcpkg (HEAD)...
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets(183,5): warning : error: in triplet x64-windows: Unable to find a valid Visual Studio instance
1>Could not locate a complete Visual Studio instance
1>The following paths were examined for Visual Studio instances:
1>    C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary/Build\vcvarsall.bat
1>    C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC/vcvarsall.bat
1>
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\scripts\buildsystems\msbuild\vcpkg.targets(183,5): error MSB3073: The command ""C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\vcpkg.exe" install  --x-wait-for-lock --triplet "x64-windows" --vcpkg-root "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg\\" "--x-manifest-root=C:\Users\kmarshal\source\repos\hexatron_viz\\" "--x-install-root=C:\Users\kmarshal\source\repos\hexatron_viz\vcpkg_installed\x64-windows\\" " exited with code 1.
1>Done building project "hexatron_viz.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 2:12 PM and took 04.273 seconds ==========

Additional context vcpkg.json

{
    "name": "hexatron",
    "dependencies": [
        "directxtk"
    ],
    "builtin-baseline": "9d47b24eacbd1cd94f139457ef6cd35e5d92cc84"
}

& 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe' -all -prerelease -legacy -products * -format xml

<?xml version="1.0"?>
<instances>
  <instance>
    <instanceId>4b174a92</instanceId>
    <installDate>2023-05-18T16:57:33Z</installDate>
    <installationName>VisualStudio/17.6.5+33829.357</installationName>
    <installationPath>C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools</installationPath>
    <installationVersion>17.6.33829.357</installationVersion>
    <productId>Microsoft.VisualStudio.Product.BuildTools</productId>
    <productPath>C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\LaunchDevCmd.bat</productPath>
    <state>4294967295</state>
    <isComplete>1</isComplete>
    <isLaunchable>1</isLaunchable>
    <isPrerelease>0</isPrerelease>
    <isRebootRequired>0</isRebootRequired>
    <displayName>Visual Studio Build Tools 2022</displayName>
    <description>The Visual Studio Build Tools allows you to build native and managed MSBuild-based applications without requiring the Visual Studio IDE. There are options to install the Visual C++ compilers and libraries, MFC, ATL, and C++/CLI support.</description>
    <channelId>VisualStudio.17.Release</channelId>
    <channelUri>https://aka.ms/vs/17/release/channel</channelUri>
    <enginePath>C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service</enginePath>
    <installedChannelId>VisualStudio.17.Release</installedChannelId>
    <installedChannelUri>https://aka.ms/vs/17/release/channel</installedChannelUri>
    <releaseNotes>https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.6#17.6.5</releaseNotes>
    <thirdPartyNotices>https://go.microsoft.com/fwlink/?LinkId=661288</thirdPartyNotices>
    <updateDate>2023-07-28T21:20:48.9717389Z</updateDate>
    <catalog>
      <buildBranch>d17.6</buildBranch>
      <buildVersion>17.6.33829.357</buildVersion>
      <id>VisualStudio/17.6.5+33829.357</id>
      <localBuild>build-lab</localBuild>
      <manifestName>VisualStudio</manifestName>
      <manifestType>installer</manifestType>
      <productDisplayVersion>17.6.5</productDisplayVersion>
      <productLine>Dev17</productLine>
      <productLineVersion>2022</productLineVersion>
      <productMilestone>RTW</productMilestone>
      <productMilestoneIsPreRelease>False</productMilestoneIsPreRelease>
      <productName>Visual Studio</productName>
      <productPatchVersion>5</productPatchVersion>
      <productPreReleaseMilestoneSuffix>1.0</productPreReleaseMilestoneSuffix>
      <productSemanticVersion>17.6.5+33829.357</productSemanticVersion>
      <requiredEngineVersion>3.6.2115.31769</requiredEngineVersion>
    </catalog>
    <properties>
      <campaignId>2030:67b194ab5a974197ae519c14ade3da60</campaignId>
      <channelManifestId>VisualStudio.17.Release/17.6.5+33829.357</channelManifestId>
      <nickname></nickname>
      <setupEngineFilePath>C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe</setupEngineFilePath>
    </properties>
  </instance>
  <instance>
    <instanceId>65c125d4</instanceId>
    <installDate>2023-07-28T20:53:52Z</installDate>
    <installationName>VisualStudio/17.6.5+33829.357</installationName>
    <installationPath>C:\Program Files\Microsoft Visual Studio\2022\Community</installationPath>
    <installationVersion>17.6.33829.357</installationVersion>
    <productId>Microsoft.VisualStudio.Product.Community</productId>
    <productPath>C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\devenv.exe</productPath>
    <state>4294967295</state>
    <isComplete>1</isComplete>
    <isLaunchable>1</isLaunchable>
    <isPrerelease>0</isPrerelease>
    <isRebootRequired>0</isRebootRequired>
    <displayName>Visual Studio Community 2022</displayName>
    <description>Powerful IDE, free for students, open-source contributors, and individuals</description>
    <channelId>VisualStudio.17.Release</channelId>
    <channelUri>https://aka.ms/vs/17/release/channel</channelUri>
    <enginePath>C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service</enginePath>
    <installedChannelId>VisualStudio.17.Release</installedChannelId>
    <installedChannelUri>https://aka.ms/vs/17/release/channel</installedChannelUri>
    <releaseNotes>https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-v17.6#17.6.5</releaseNotes>
    <thirdPartyNotices>https://go.microsoft.com/fwlink/?LinkId=661288</thirdPartyNotices>
    <updateDate>2023-07-28T20:53:52.7170112Z</updateDate>
    <catalog>
      <buildBranch>d17.6</buildBranch>
      <buildVersion>17.6.33829.357</buildVersion>
      <id>VisualStudio/17.6.5+33829.357</id>
      <localBuild>build-lab</localBuild>
      <manifestName>VisualStudio</manifestName>
      <manifestType>installer</manifestType>
      <productDisplayVersion>17.6.5</productDisplayVersion>
      <productLine>Dev17</productLine>
      <productLineVersion>2022</productLineVersion>
      <productMilestone>RTW</productMilestone>
      <productMilestoneIsPreRelease>False</productMilestoneIsPreRelease>
      <productName>Visual Studio</productName>
      <productPatchVersion>5</productPatchVersion>
      <productPreReleaseMilestoneSuffix>1.0</productPreReleaseMilestoneSuffix>
      <productSemanticVersion>17.6.5+33829.357</productSemanticVersion>
      <requiredEngineVersion>3.6.2115.31769</requiredEngineVersion>
    </catalog>
    <properties>
      <campaignId>2030:84b5ca0345284936a000d312647956e2</campaignId>
      <channelManifestId>VisualStudio.17.Release/17.6.5+33829.357</channelManifestId>
      <nickname>2</nickname>
      <setupEngineFilePath>C:\Program Files (x86)\Microsoft Visual Studio\Installer\setup.exe</setupEngineFilePath>
    </properties>
  </instance>
  <instance>
    <instanceId>VisualStudio.14.0</instanceId>
    <installationPath>C:\Program Files (x86)\Microsoft Visual Studio 14.0\</installationPath>
    <installationVersion>14.0</installationVersion>
  </instance>
</instances>
kylecmarshall commented 1 year ago

I solved the issue by uninstalling Visual Studio 2022 Build Tools.

The issue is caused when vcpkg is trying to determine the preferred instance of visual studio to use. It uses a comparator preferred_first_comparator:

https://github.com/microsoft/vcpkg-tool/blob/ec414a723f9280338857f2187683585eee8616a5/src/vcpkg/visualstudio.cpp#L49-L67

Visual Studio 2022 Community and Visual Studio 2022 Build Tools are equivalent under this comparator which causes SortedVector to remove one of them in its uniqueify:

https://github.com/microsoft/vcpkg-tool/blob/ec414a723f9280338857f2187683585eee8616a5/include/vcpkg/base/sortedvector.h#L88-L107

Visual Studio 2022 Community was the unlucky one and it got erased from the list of possible instances before further checking even began.

So a duct tape solution is to just uninstall Build Tools so that it doesn't show up in vswhere. This allows VS 2022 Community to stay in the list of possible instances. A better solution would be to update preferred_first_comparator to split the equivalence class between Build Tools and VS that have the exact same version number.

kylecmarshall commented 1 year ago

I thought about this yesterday and another solution might be to use a different sorted vector that keeps equivalent elements.

jimwang118 commented 1 year ago

Thanks for your suggestion, we will think about ways to fix this issue.

Shivang44 commented 11 months ago

So a duct tape solution is to just uninstall Build Tools so that it doesn't show up in vswhere. This allows VS 2022 Community to stay in the list of possible instances. A better solution would be to update preferred_first_comparator to split the equivalence class between Build Tools and VS that have the exact same version number.

Oh my god thank you, wasted hours on this issue and this is the only thing that worked for me!

github-actions[bot] commented 5 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 180 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.

kikonen commented 2 months ago

Just hit "Could not locate a complete Visual Studio instance" issue after updating to "Visual Studio Community 2022 17.10.0". Clearly doing such update was mistake since now cannot build project, due to this peculiar error from vcpkg.

1>EXEC : error : in triplet x64-windows: Unable to find a valid Visual Studio instance
1>Could not locate a complete Visual Studio instance
1>The following paths were examined for Visual Studio instances:
1>    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary/Build\vcvarsall.bat

Seeming somebody else hit same (https://developercommunity.visualstudio.com/t/VCPKG-fails-with-VS-v17100/10663893?sort=newest), and Microsoft support unhelpfully just pointed into vcpkg.

(trying to revert back to previous visual studio version which, was not breaking vcpkg)

CraftSpider commented 1 week ago

Running into this with VS 17.10.5. It would be nice if this could be fixed, as it's quite a pain for me working on projects that usee vcpkg.

sfhacker commented 1 week ago

This embarrassing open issue is one year old! God save us all!

EastArctica commented 1 day ago

So a duct tape solution is to just uninstall Build Tools so that it doesn't show up in vswhere. This allows VS 2022 Community to stay in the list of possible instances. A better solution would be to update preferred_first_comparator to split the equivalence class between Build Tools and VS that have the exact same version number.

This workaround doesn't work for me, I removed the build tools and rebooted but yet am still unable to compile.

This really needs to be fixed, we can't be telling people to uninstall build tools to solve their problems.

sfhacker commented 1 day ago

This is NOT sustainable!