TorchSharp: Can't compile TorchSharp.sln with Visual Studio

OS: Windows 11 Have installed VS 2019 and VS 2022. CMake is installed, user path to it is set:

C:\Temp\github-clean\TorchSharp>cmake --version
cmake version 3.21.3

CMake suite maintained and supported by Kitware (kitware.com/cmake).

I could compile and run tests from command line, but build fails in VS. Tried VS 2022 first, now VS 2019, no luck. Below is the VS 2019 build output after cloning, opening TorchSharp.sln and trying to build.

Build started...
1>------ Build started: Project: TorchSharp (src\TorchSharp), Configuration: Debug Any CPU ------
1>Using VersionSuffix =
1>Using Version = 0.96.0
1>C:\Temp\github-clean\TorchSharp\src\Native\build.cmd Debug x64 --libtorchpath C:\Temp\github-clean\TorchSharp\bin/obj/AnyCPU.Debug\libtorch-cpu\libtorch-win-shared-with-deps-debug-1.10.0cpu\libtorch\share\cmake\Torch
1>The system cannot find the path specified.
1>Commencing native build of dotnet/machinelearning
1>
1>Calling "C:\Temp\github-clean\TorchSharp\src\Native\\gen-buildsys-win.bat" "C:\Temp\github-clean\TorchSharp\src\Native\" "16 2019" x64
1>"C:\Program Files\CMake\bin\cmake.exe" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_INSTALL_PREFIX=C:/Temp/github-clean/TorchSharp/src/Native/../../bin/x64.Debug/Native" "-DLIBTORCH_PATH=C:\Temp\github-clean\TorchSharp\bin/obj/AnyCPU.Debug\libtorch-cpu\libtorch-win-shared-with-deps-debug-1.10.0cpu\libtorch\share\cmake\Torch" -G "Visual Studio 16 2019"  -A x64 -B. -H"C:\Temp\github-clean\TorchSharp\src\Native\"
1>CMake Warning (dev) in CMakeLists.txt:
1>  No project() command is present.  The top-level CMakeLists.txt file must
1>  contain a literal, direct call to the project() command.  Add a line of
1>  code such as
1>
1>    project(ProjectName)
1>
1>  near the top of the file, but after cmake_minimum_required().
1>
1>  CMake is pretending there is a "project(Project)" command on the first
1>  line.
1>This warning is for project developers.  Use -Wno-dev to suppress it.
1>
1>-- The C compiler identification is MSVC 19.29.30139.0
1>-- The CXX compiler identification is MSVC 19.29.30139.0
1>-- Detecting C compiler ABI info
1>-- Detecting C compiler ABI info - done
1>-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1>-- Detecting C compile features
1>-- Detecting C compile features - done
1>-- Detecting CXX compiler ABI info
1>-- Detecting CXX compiler ABI info - done
1>-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
1>-- Detecting CXX compile features
1>-- Detecting CXX compile features - done
1>CMake Error at LibTorchSharp/CMakeLists.txt:7 (find_package):
1>  Could not find a package configuration file provided by "Torch" with any of
1>  the following names:
1>
1>    TorchConfig.cmake
1>    torch-config.cmake
1>
1>  Add the installation prefix of "Torch" to CMAKE_PREFIX_PATH or set
1>  "Torch_DIR" to a directory containing one of the above files.  If "Torch"
1>  provides a separate development package or SDK, be sure it has been
1>  installed.
1>
1>
1>-- Configuring incomplete, errors occurred!
1>See also "C:/Temp/github-clean/TorchSharp/bin/obj/x64.Debug/Native/CMakeFiles/CMakeOutput.log".
1>Failed to generate native component build project!
1>C:\Temp\github-clean\TorchSharp\src\Native\build.proj(53,5): error MSB3073: The command ""C:\Temp\github-clean\TorchSharp\src\Native\build.cmd" Debug x64 --libtorchpath C:\Temp\github-clean\TorchSharp\bin/obj/AnyCPU.Debug\libtorch-cpu\libtorch-win-shared-with-deps-debug-1.10.0cpu\libtorch\share\cmake\Torch" exited with code 1.
1>Done building project "build.proj" -- FAILED.
2>------ Build started: Project: FileRestitcher, Configuration: Debug Any CPU ------
2>FileRestitcher -> C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\FileRestitcher\netstandard2.0\FileRestitcher.dll
3>------ Build started: Project: FileRestitcher.Tests, Configuration: Debug Any CPU ------
3>FileRestitcher.Tests -> C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\FileRestitcher.Tests\net5.0\FileRestitcher.Tests.dll
4>------ Build started: Project: Examples.Utils, Configuration: Debug Any CPU ------
4>CSC : error CS0006: Metadata file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\TorchSharp\netcoreapp3.1\TorchSharp.dll' could not be found
4>Done building project "Examples.Utils.csproj" -- FAILED.
5>------ Build started: Project: TorchSharpTest, Configuration: Debug Any CPU ------
5>CSC : error CS0006: Metadata file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\TorchSharp\netcoreapp3.1\TorchSharp.dll' could not be found
5>Done building project "TorchSharpTest.csproj" -- FAILED.
6>------ Build started: Project: TorchSharpTest.WithCudaBinaries, Configuration: Debug Any CPU ------
6>CSC : error CS0006: Metadata file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\TorchSharp\netcoreapp3.1\TorchSharp.dll' could not be found
6>Done building project "TorchSharpTest.WithCudaBinaries.csproj" -- FAILED.
7>------ Build started: Project: Examples, Configuration: Debug Any CPU ------
7>CSC : error CS0006: Metadata file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\Examples.Utils\net5.0\ref\Examples.Utils.dll' could not be found
7>CSC : error CS0006: Metadata file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\TorchSharp\netcoreapp3.1\TorchSharp.dll' could not be found
7>Done building project "Examples.csproj" -- FAILED.
8>------ Build started: Project: FSharp.Examples, Configuration: Debug Any CPU ------
8>FSC : error FS0078: Unable to find the file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\Examples.Utils\net5.0\Examples.Utils.dll' in any of C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0\ref\net5.0 C:\Temp\github-clean\TorchSharp\src\FSharp.Examples c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\commonextensions\microsoft\fsharp\Tools\
8>FSC : error FS0078: Unable to find the file 'C:\Temp\github-clean\TorchSharp\bin\AnyCPU.Debug\TorchSharp\netcoreapp3.1\TorchSharp.dll' in any of C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0\ref\net5.0 C:\Temp\github-clean\TorchSharp\src\FSharp.Examples c:\program files (x86)\microsoft visual studio\2019\professional\common7\ide\commonextensions\microsoft\fsharp\Tools\
8>Done building project "FSharp.Examples.fsproj" -- FAILED.
========== Build: 2 succeeded, 6 failed, 0 up-to-date, 0 skipped ==========

So, if I read https://github.com/dotnet/TorchSharp/blob/main/DEVGUIDE.md and run in command line:

dotnet build /p:SkipNative=true
dotnet build  # for cuda support on Windows and Linux
dotnet test

everything is fine, but if I open sln in VS, build fails.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (12 by maintainers)

Most upvoted comments

@peteryang1 – msbuild.exe should already be on the path if you start VS from the VS command line rather than from the desktop.

1:

clang --help
'clang' is not recognized as an internal or external command,
operable program or batch file.
  1. Nope, I don’t have that installed, either.

Which makes sense to me, since we’re using MSVC to build TorchSharp on Windows.