LNK1104 error for debug build in pybind11 project on visual studio with cmake & vcpkg (Windows) - cmake

I have created a PyBind11 project on Visual Studio using CMake & VCPkg on Windows platform. I'm exposing C++ functionality in Python.
I have pybind11_x64-windows & python3.10_x64-windows installed via vcpkg and CMake3.24.1 installed through Visual Studio 2019 Professional separately.
I have the necessary CMakeLists.txt file in the project's root directory. The project builds correctly in Release mode, but in the Debug mode, I have linker error:
LINK : fatal error LNK1104: cannot open file 'python310.lib'
I don't understand, why Visual Studio needs python310.lib instead of python310_d.lib in the Debug mode. In VisualStudio, when I checked the Project->Property->Linker->Input->AdditionalDependencies, it correctly points to python310_d.lib.
I found this article on Google which seems relevant to some extent:
https://discourse.paraview.org/t/debug-build-fail-cannot-open-file-python310-lib/9000
but there doesn't seem to be a clear solution.
Is this a bug in VCPkg/CMake/Python or something else ? Does anyone have a solution to this ?

Related

Statically linked WebView2Loader produce invalid binary

We are trying to integrate WebView2 into our Win32 application, and it is working fine when it links to WebView2Loader.dll.lib to load WebView2Loader.dll.
We followed the MSDN instructions to link the library statically, and this has so far failed to work. There are no errors output during the build, and even with diagnostic setting all looks perfectly correct.
However, the executable produced does not have a valid PE header.
We are building an x86 executable, and it is linking with WebView2LoaderStatic.lib from the x86 folder of the WebView2 package, as downloaded with NuGet.
The used environment is:
Visual Studio 2017, with all updates installed, Build Toolset 141, Target Platform is Windows 10, Windows SDK Version is 10.0.17763.0
Update 1: We have discovered that if "Generate Debug Info" in Linker Options is turned off, a valid binary is generated. However, this is not a good solution for us in debug mode, so any ideas that might help would be deeply appreciated. Our temporary solution is to edit the project file to conditionally set the static linkage flag only when doing release builds, and ensure those doesn't contain debug info.

Cannot build Python.NET Python.Runtime in Visual Studio from master, or via setup.py

I tried to "Build Solution" from Visual Studio 2019, since the Python.NET project comes with a .sln VS Solution file
However, it skipped the Python.Runtime build which is what I'm interested in:
1>------ Skipped Build: Project: Python.Runtime ------
Furthermore, the other 4 builds had an error:
3>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.targets(186,5): error : Your project file doesn't list 'win-x64' as a "RuntimeIdentifier". You should add 'win-x64' to the "RuntimeIdentifiers" property in your project file and then re-run NuGet restore.
Alternatively, when running python setup.py following instructions on https://github.com/pythonnet/pythonnet/wiki/Installation#github-installation-from-master-branch, I ran into another error from not being able to find Windows Kits installed roots. Have been looking around for answers and tried different versions of Python, .NET Core, .NET etc. to no avail. I detailed it in https://github.com/pythonnet/pythonnet/issues/1272
Environment
Pythonnet version: 3.0 (ongoing, latest master branch ending at c81c3c3)
Python version: 3.7.9
Operating System: Windows 10, 64bit, WinPE
I just loaded pythonnet.15.sln instead of pythonnet.sln and was able to build the DLL file.
Although I'm still not sure why pythonnet.sln didn't work for me, does "15" refer to the VS version? The regular sln was being used in this screenshot from a talk https://youtu.be/P7Or7XzeIno?t=1163

Open CMake proejct in Visual Studio 2019 using command line

I use Visual Studio IDE to develop, VS C++ to compile, CMake to generate the project in VS and Ninja to build.
I have a script that clone a project from git server and automate several steps I need to perform before start working on it.
At the end of this script I would like to open the project in Visual Studio. Before I used to generate the VS solution instead and then use devenv with the sln file as a parameter to open it. But now that I use VS support for CMake if I use CMakeList.txt file as a parameter it only opens this file not the complete project.
Is there a way to do what I am trying to do??
Thanks in advance.
Assuming your project's root CMakeLists.txt is located in C:\project\CMakeLists.txt you can call
devenv "C:\project"
without the CMakeLists.txt.
Note that currently there seems to be a bug in Visual Studio 16.7 that when opening a directory, all the views (e.g. solution explorer) are hidden by default. (https://developercommunity.visualstudio.com/content/problem/1140297/visual-studio-is-forgetting-docked-viewwindow-layo.html)

Microsoft.Windows.UI.Xaml.CSharp.targets missing on CI server

Problem
I just committed the addition of a UWP application to source control. However, my CI server (Jenkins) didn't seem to like that:
error MSB4019: The imported project "C:\Program Files
(x86)\MSBuild\Microsoft\WindowsXaml\v14.0\Microsoft.Windows.UI.Xaml.CSharp.targets"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
This is stemming from the following UWP project file import:
<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
On my local machine, I can see this file located at:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.Targets
Obviously, this is due to my local installation of Visual Studio 2017. However, the CI server does not have Visual Studio installed. I imagine this is why MSBuildExtensionsPath is resolving to the path mentioned in the error instead.
Dependencies
The following items are already installed on the CI server:
Visual Studio Build Tools 2017 (download)
Windows 10 SDK 10.0.15063.468 (download)
Xamarin.VisualStudio 4.5.0.476 (download)
.NET Framework 4.5.1-4.7 SDKs
I assumed these would include the necessary dependencies, but I cannot find Microsoft.Windows.UI.Xaml.CSharp.targets anywhere.
Workaround
Copying the directory on my local machine
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\WindowsXaml\v15.0
to the CI server at
C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0
seems to resolve the error, but it feels very hacky.
Question
Is there a way to resolve this without installing Visual Studio 2017 on the CI server or copying/renaming files manually?
UPDATE 2018-01-12:
This is still an issue with the latest version of VSBT. The only thing to report is the error changed from v14 to v15. After copying the same directory over to v15, the error is gone again. However, another seemingly unrelated error shows up:
C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1124,5):
error MSB3644: The reference assemblies for framework
".NETCore,Version=v5.0" were not found. To resolve this, install the
SDK or Targeting Pack for this framework version or retarget your
application to a version of the framework for which you have the SDK
or Targeting Pack installed. Note that assemblies will be resolved
from the Global Assembly Cache (GAC) and will be used in place of
reference assemblies. Therefore your assembly may not be correctly
targeted for the framework you intend.
UPDATE 2018-01-15
.NETCore,Version=v5.0 error resolved by copying the following directory from my local machine to the build server:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v5.0
While the UWP build is successful, no appxbundle is generated. This seems to indicate another dependency is missing from VSBT.

Cannot build .net core 1.1 with msbuild tools

I have a .net core class library I am attempting to build into a nugget package. however, on my build server (running team city), I am getting the following error:
C:\TeamCity\buildAgent\work\3c6531587491c25e\MySolution\MyProject.csproj
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft
Visual
Studio\2017\BuildTools\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props"
was not found. Confirm that the path in the declaration is
correct, and that the file exists on disk.
When I look in this directory, I ma missing the "Microsoft.NET.Sdk" folder from my build server. where do I get these tools without having to install visual studio?
Thanks!
See the tracking issue on GitHub: https://github.com/Microsoft/msbuild/issues/1697
If you don't want to touch your build tools installation (by copying SDK files), you can also set the MSBuildSDKsPath environment variable to the location of the SDKs carried in the .net CLI (usually C:\Program Files\dotnet\sdk\1.0.0\Sdks\)