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

"Unable to determine the correct CMake Generator for Visual Studio" #7324

Closed
RussKie opened this issue Apr 30, 2021 · 10 comments · Fixed by #7342 or #7543
Closed

"Unable to determine the correct CMake Generator for Visual Studio" #7324

RussKie opened this issue Apr 30, 2021 · 10 comments · Fixed by #7342 or #7543
Assignees

Comments

@RussKie
Copy link
Member

RussKie commented Apr 30, 2021

I have VS17 installed, and now trying to build dotnet/winforms from cli fails due to the following error message:

C:\Users\user\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(53,5): error : Unable to determine the correct CMake Generator for Visual Studio. The SDK may need to be updated to understand a new VS version. Unknown Visual Studio version 17.0.31222.107 [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]

Naively I tried to change Microsoft.DotNet.CMake.Sdk.targets to:

    <PropertyGroup>
      <VSGenerator Condition="$(_HighestCompatibleVSVersion.StartsWith(16.))">Visual Studio 16 2019</VSGenerator>
+     <VSGenerator Condition="$(_HighestCompatibleVSVersion.StartsWith(17.))">Visual Studio 17 2020</VSGenerator>
    </PropertyGroup>

But this fails even more spectacularly:

EXEC : CMake error : Could not create named generator Visual Studio 17 2020 [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]
  
  Generators
  * Visual Studio 16 2019        = Generates Visual Studio 2019 project files.
                                   Use -A option to specify architecture.
    Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
                                   Optional [arch] can be "Win64" or "ARM".
    Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
                                   Optional [arch] can be "Win64" or "ARM".
    Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
                                   Optional [arch] can be "Win64" or "ARM".
    Visual Studio 11 2012 [arch] = Generates Visual Studio 2012 project files.
                                   Optional [arch] can be "Win64" or "ARM".
    Visual Studio 10 2010 [arch] = Generates Visual Studio 2010 project files.
                                   Optional [arch] can be "Win64" or "IA64".
    Visual Studio 9 2008 [arch]  = Generates Visual Studio 2008 project files.
                                   Optional [arch] can be "Win64" or "IA64".
    Borland Makefiles            = Generates Borland makefiles.
    NMake Makefiles              = Generates NMake makefiles.
    NMake Makefiles JOM          = Generates JOM makefiles.
    MSYS Makefiles               = Generates MSYS makefiles.
    MinGW Makefiles              = Generates a make file for use with
                                   mingw32-make.
    Unix Makefiles               = Generates standard UNIX makefiles.
    Green Hills MULTI            = Generates Green Hills MULTI files
                                   (experimental, work-in-progress).
    Ninja                        = Generates build.ninja files.
    Ninja Multi-Config           = Generates build-<Config>.ninja files.
    Watcom WMake                 = Generates Watcom WMake makefiles.
    CodeBlocks - MinGW Makefiles = Generates CodeBlocks project files.
    CodeBlocks - NMake Makefiles = Generates CodeBlocks project files.
    CodeBlocks - NMake Makefiles JOM
                                 = Generates CodeBlocks project files.
    CodeBlocks - Ninja           = Generates CodeBlocks project files.
    CodeBlocks - Unix Makefiles  = Generates CodeBlocks project files.
    CodeLite - MinGW Makefiles   = Generates CodeLite project files.
    CodeLite - NMake Makefiles   = Generates CodeLite project files.
    CodeLite - Ninja             = Generates CodeLite project files.
    CodeLite - Unix Makefiles    = Generates CodeLite project files.
    Sublime Text 2 - MinGW Makefiles
                                 = Generates Sublime Text 2 project files.
    Sublime Text 2 - NMake Makefiles
                                 = Generates Sublime Text 2 project files.
    Sublime Text 2 - Ninja       = Generates Sublime Text 2 project files.
    Sublime Text 2 - Unix Makefiles
                                 = Generates Sublime Text 2 project files.
    Kate - MinGW Makefiles       = Generates Kate project files.
    Kate - NMake Makefiles       = Generates Kate project files.
    Kate - Ninja                 = Generates Kate project files.
    Kate - Unix Makefiles        = Generates Kate project files.
    Eclipse CDT4 - NMake Makefiles
                                 = Generates Eclipse CDT 4.0 project files.
    Eclipse CDT4 - MinGW Makefiles
                                 = Generates Eclipse CDT 4.0 project files.
    Eclipse CDT4 - Ninja         = Generates Eclipse CDT 4.0 project files.
    Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.

C:\Users\user\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(176,5): error MSB3073: The command " [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj] 
C:\Users\user\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(176,5): error MSB3073:        [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]        
C:\Users\user\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(176,5): error MSB3073:        [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]        
C:\Users\user\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(176,5): error MSB3073:        cmake -G "Visual Studio 17 2020" -A x64 -B "C:\Development\winforms\artifacts\obj\NativeTests\x64\Debug" -S "C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests" -DCMAKE_INSTALL_PREFIX=C:\Development\winforms\artifacts\bin\NativeTests\x64\Debug [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]
C:\Users\igveliko\.nuget\packages\microsoft.dotnet.cmake.sdk\6.0.0-beta.21076.1\build\Microsoft.DotNet.CMake.Sdk.targets(176,5): error MSB3073:       " exited with code 1. [C:\Development\winforms\src\System.Windows.Forms\tests\InteropTests\NativeTests\NativeTests.proj]

The follow change seems to work:

  <PropertyGroup Condition="$([MSBuild]::IsOsPlatform(Windows))">
    <VSWherePath>$([MSBuild]::NormalizePath('$(Pkgvswhere)','tools','vswhere.exe'))</VSWherePath>
    <_VSNativeCompilerComponentArchName Condition="'$(Platform)' == 'x86'">x86.x64</_VSNativeCompilerComponentArchName>
    <_VSNativeCompilerComponentArchName Condition="'$(Platform)' == 'x64'">x86.x64</_VSNativeCompilerComponentArchName>
    <_VSNativeCompilerComponentArchName Condition="'$(Platform)' == 'arm'">ARM</_VSNativeCompilerComponentArchName>
    <_VSNativeCompilerComponentArchName Condition="'$(Platform)' == 'arm64'">ARM64</_VSNativeCompilerComponentArchName>
    <_VSNativeCompilerComponentName>Microsoft.VisualStudio.Component.VC.Tools.$(_VSNativeCompilerComponentArchName)</_VSNativeCompilerComponentName>
+   <_VSTargetRange>"[16.0,16.99)"</_VSTargetRange>
  </PropertyGroup>

    <Exec
-     Command="$(VSWherePath) -latest -prerelease -products * -requires $(_VSNativeCompilerComponentName) -property installationVersion"
+     Command="$(VSWherePath) -latest -prerelease -version $(_VSTargetRange) -products * -requires $(_VSNativeCompilerComponentName) -property installationVersion"
      EchoOff="true"
      ConsoleToMsBuild="true"
      StandardOutputImportance="Low">
      <Output TaskParameter="ConsoleOutput" PropertyName="_HighestCompatibleVSVersion" />
    </Exec>
@MattGal
Copy link
Member

MattGal commented May 6, 2021

[Async Triage]: Seems worth doing and given VS 2017 is still supported something we should do. Doesn't seem like FR unless it's totally blocking.

@RussKie can it be assumed you don't want to move to VS 2019?

@jkoritzinsky
Copy link
Member

VS17 in this case is Dev17, which is unreleased.

@jkoritzinsky
Copy link
Member

VS2017 is Dev15

@MattGal
Copy link
Member

MattGal commented May 6, 2021

Ah. In that case, seems like this could wait until the public previews exist.

@jkoritzinsky
Copy link
Member

I already have a PR with a fix out at #7342 if you want to take a look. I put it out a few days ago.

@MattGal
Copy link
Member

MattGal commented May 6, 2021

Sure, approved. "VS17" is just too ambiguous and we really should just use a non-year version scheme....

@RussKie
Copy link
Member Author

RussKie commented Jun 21, 2021

This change doesn't appear to work. I have now reinstalled VS 17.0.0 Preview 2.0 [31418.319.main]:
image
image

C:\Development\winforms>C:\Users\igveliko\.nuget\packages\vswhere\2.6.7\tools\vswhere.exe -latest -prerelease -products * -version [,17.0) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion
17.0.31418.319

C:\Development\winforms>C:\Users\igveliko\.nuget\packages\vswhere\2.6.7\tools\vswhere.exe -products * -version [,17.0) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion
16.10.31410.357

C:\Development\winforms>C:\Users\igveliko\.nuget\packages\vswhere\2.6.7\tools\vswhere.exe -prerelease -products * -version [,17.0) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion
16.11.31418.215
17.0.31418.319
16.10.31410.357

Looks like it may be a bug in vswhere, but right now I can't build dotnet/winforms.

@RussKie RussKie reopened this Jun 21, 2021
@RussKie
Copy link
Member Author

RussKie commented Jun 21, 2021

I also tried VSWhere 2.8.4, and the results are the same.

@RussKie
Copy link
Member Author

RussKie commented Jun 21, 2021

Raised microsoft/vswhere#238

@RussKie
Copy link
Member Author

RussKie commented Jun 21, 2021

This seems to work - note the lower boundary is set:

C:\Development\winforms>C:\Users\igveliko\.nuget\packages\vswhere\2.8.4\tools\vswhere.exe -latest -prerelease -products * -version [15,17.0) -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationVersion
16.11.31418.215

Not sure what the lowest version we want to support though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants