When using CMakePresets.json, what is the equivalent of remotePreGenerateCommand? - visual-studio-2022

I am trying to switch from CMakeSettings.json to CMakePresets.json in a Visual Studio CMake project targetting Linux.
In my current CMakeSettings.json, I used to activate a Conda environment before generating the CMake cache on remote systems (including WSL) with:
{
...
"remotePreGenerateCommand": "conda activate foobar",
}
What would be the equivalent feature with CMakePresets.json? I could not find anything similar in the Visual Studio Remote Settings vendor map.

Related

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

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 ?

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

How to set the default MSVC compiler version when multiple versions exist for same toolset version

I have multiple versions of MSVC C++ build tools for the same toolset(v142) installed using Visual studio build tools. How can I set the default or preferred version of the MSVC compiler. Is there a registry or environment variable for setting this in Windows or with Cmake?
Cmake picks up the latest version and I want it to use older version for some builds. CMake does seem to have a -T parameter for toolset but in my case both versions are for toolset v142.
Please note that I do not have or intend to use Visual Studio IDE for this since I am dealing with command line builds for CI purposes.
You can pass the required version via CLI:
$ cmake ... -T v142,version=14.24
See also CMAKE_GENERATOR_TOOLSET variable.

How can I install the VS2017 version of msbuild on a build server without installing the IDE?

Historically, this has been done with the Microsoft Build Tools. But it seems that the Build Tools may not be available for versions after 2015. The replacement appears to be the Visual Studio build tools, which doesn't seem to have a real homepage yet.
I downloaded the VS2017 Professional installer, and went to the Individual Components tab. Right away, the summary is telling me that the Visual Studio core editor is there, taking up 753MB. I don't want the editor. Just msbuild. There is no way to unselect the editor.
Is there a way I can install the latest version of msbuild without also installing the Visual Studio IDE?
The Visual Studio Build tools are a different download than the IDE. They appear to be a pretty small subset, and they're called Build Tools for Visual Studio 2019 (download).
You can use the GUI to do the installation, or you can script the installation of msbuild:
vs_buildtools.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --quiet
Microsoft.VisualStudio.Workload.MSBuildTools is a "wrapper" ID for the three subcomponents you need:
Microsoft.Component.MSBuild
Microsoft.VisualStudio.Component.CoreBuildTools
Microsoft.VisualStudio.Component.Roslyn.Compiler
You can find documentation about the other available CLI switches here.
The build tools installation is much quicker than the full IDE. In my test, it took 5-10 seconds. With --quiet there is no progress indicator other than a brief cursor change. If the installation was successful, you should be able to see the build tools in %programfiles(x86)%\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin.
If you don't see them there, try running without --quiet to see any error messages that may occur during installation.
For MsBuild 17, which is part of VS2022, you need to download the Build tools for VS2022 here (which is actually just the installer):
https://aka.ms/vs/17/release/vs_BuildTools.exe
(This link can be found by going to https://visualstudio.microsoft.com/downloads and scrolling all the way down to "Build Tools for Visual Studio 2022".)
Once downloaded you can install by typing:
vs_buildtools.exe --add Microsoft.VisualStudio.Workload.MSBuildTools --quiet --wait
Depending on your needs you might also need to specify --includeRecommended and possibly --includeOptional.
If you are doing web development you probably also want to add --add Microsoft.VisualStudio.Workload.WebBuildTools.
Input parameters and return codes are available here:
https://learn.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio?view=vs-2022

How to run .NET 4 code analysis on build server

On a Windows Server 2003 R2 with .NET 4 SDK but without Visual Studio 2010, I have tried building a Visual Studio 2010 solution with
msbuild MySolution.sln /p:RunCodeAnalysis=true
but that fails.
What is required to run code analysis on such an environment?
I get this error message:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(129,9): error MSB6003:
The specified task executable "FxCopCmd.exe" could not be run.
Could not load file or assembly
'Microsoft.VisualStudio.CodeAnalysis.Sdk, Version=10.0.0.0, Culture=neutral, PublicKeyToken= b03f5f7f11d50a3a'
or one of its dependencies.
The system cannot find the file specified.
I have installed FxCop from the SDK and without luck pointed the variable FxCopDir to the installed location of FxCopCmd.exe, and also setting this registry entry to that location:
HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev#FxCopDir
I had the same problem on my MSBuild server and fixed it by:
Installing Windows SDK 7.1
Setting up the registry keys FxCopDir and StanDir in HKEY_LOCAL_MACHINE\Software\Microsoft\VisualStudio\10.0\Setup\EDev (in Win32).
I then copied over from the dev PC, to the FxCop folder on the build server, the following:
The folder Rule Sets (default installation target is here: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop)
Microsoft.VisualStudio.CodeAnalysis.Sdk.dll
Microsoft.VisualStudio.CodeAnalysis.Phoenix.dll
phx.dll
Do a search for them on your dev PC with Visual Studio installed to locate them.
Then use the .NET 4.0 version of gacutil.exe to install Microsoft.VisualStudio.CodeAnalysis.Sdk.dll to the GAC.
You should then be able to run code analysis as part of an MSBuild build and have it work properly.
An alternative to FxCop would be to use the tool NDepend that lets write Code Rules over C# LINQ Queries (namely CQLinq). Disclaimer: I am one of the developers of the tool
More than 200 code rules are proposed by default. Customizing existing rules or creating your own rules is straightforward thanks to the well-known C# LINQ syntax.
Rules can be verified live in Visual Studio and at Build Process time, in a generated HTML+javascript report.
Another option might be calling FxCop executable as a build task (from msbuildtasks), saving the result as an XML file that can be parsed within most of the CI tools (like Hudson and CC.NET)