Unable to add Google Test NuGet package to a Visual Studio Linux C++ project - c++

I have a Linux C++ project in Visual Studio 2017 which contains unit tests, and I'm trying to add the Google test framework to it. I have added the gtest NuGEt package to the project, and in every file that uses this, I have a #include "gtest/gtest.h". This works fine in a Windows-based unit test project, but in the Linux C++ project (all else being equal as far as I can tell), the NuGet package doesn't seem to be able to work, and when I compile I get the following error :
gtest/gtest.h: No such file or directory.
Does anyone know why this doesn't work?

That's because VS Linux projects are compiled and executed on a connected Linux machine (see Tools / Options / Connection Manager). Which in your case does not have Gtest installed.

Related

Installing OR-Tools to Visual Studio 2022

I am trying to write a code using Google's OR-Tools on Microsoft Visual Studio 2022.
I followed the following steps:
Download OR-Tools from Binary on Windows on their website.
Extracted the .zip file in D:\CodeField
Wrote the complete TSP programs of their website on VS.
In Visual Studio, went to Project > Properties > C/C++ > Additional Include Directories
Added "D:\CodeField\or-tools_x64_VisualStudio2022_cpp_v9.5.2237\include"
Clicked Apply then OK then compiled my code.
I am getting a bunch of linking errors "1>ortools.lib(scip_callback.obj) : error LNK2001: unresolved external symbol SCIPconshdlrGetData".
what should I do?
Try adding the lib folder in linker settings and link ortools_full.lib. If there are other errors try changing the runtime library to /MD. Make sure you use C++17.
Visual Studio
To build and run OR-Tools on Windows, you must have Visual Studio 2019 or later installed on your computer with the C++ toolset for Visual Studio.
You can find more details here.
To build OR-Tools programs from the command line you must use a x64 Native Tools Command Prompt (not the Developer Command Prompt).
You can find more details here.
Git
Git, which can be downloaded from https://git-scm.com/.
CMake
CMake (>= 3.18), which can be downloaded from https://www.cmake.org/download. When installing CMake, select the option for a command-line accessible cmake.
.NET Core 3.1 SDK
You must install the package .NET Core 3.1 SDK version 3.1.100 or higher from the following location: sdk-3.1.425-windows-x64-installer
.Net 6.0 SDK
You must install the package .NET 6.0 SDK from the following location: sdk-6.0.403-windows-x64-installer
Download the source code
There are two distinct branches of the OR-Tools source code on GitHub: stable and main.
The stable branch has been thoroughly tested and should work flawlessly on all supported platforms.
The main branch is where the latest updates and improvements have been applied; it's more current, but less stable.

Building and running unit tests with Visual Studio build tools

I am adding unit tests to an existing C++ Visual Studio projects, using the Google Test adapter.
It's all running fine on my computer with Visual Studio 2019, but when I try to run them on the build server I get the following error
error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.1.8.1.3\build\native\Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn.targets.
However, we're not using NuGet for package management. I tried installing it but complained about missing folders. This is not a .NET project, so I think that's a red herring.
I was able to install the Google Test adapter on my computer using the Visual Studio Installer, but it does not show up as a part of the VS Build Tools on the build server.
Running msbuild -t:restore does not help, it just reports "nothing to do."
I don't understand why the Google Test adapter isn't available for VS Build Tools, since it seems to be required in order to build the unit tests. Does anyone know why it doesn't work? What's the best practice for handling this?
Thanks!
The problem is that your c++ project has missed the content of googletest nuget package. So the solution is to restore the whole nuget package in your c++ project.
Update 1
First of all, take a brand new backed up project and restore it to when the problem started.
Besides, msbuild -t:restore command applies to projects with PackageReference nuget management format.
Since your c++ project used packages.config nuget management format, msbuild -t:restore will not work. See this official document.Instead, you should use nuget restore command.
This command works for your current project and running this command will restore the nuget packages and then you will never face the issue.
Before using it, you should download nuget.exe CLI and config its path into System Environment Variable PATH so that CMD can invoke nuget.
The steps about configing nuget.exe, you can refer to this link.
Steps
1) delete packages folder under the solution folder
2)Then, open build tool, run:
nuget restore xxx\xxx\xxx.sln(the full path of solution file containing the c++ project and the unit test project)
Then, you can build the project with the command. And I hope the error will disappear.

NServiceBus.Host.exe is missing while installing NServiceBus.Host on aspnetcore 2 in visual studio 2017

I am trying to run NServiceBus with AspNetCore2 on visual studio 2017. While I install NServiceBus(Version 7.0.0-beta0001) and NServiceBus.Host(Version 8.0.0-beta0001) through nuget, it says package installed successfully.
However, when i try to check installed dll's and exe files of NServiceBus within bin/debug folder, it's not there.
Quick observations i made are, NServiceBus (version 7.0...) is installed correctly whereas NServiceBus.Host (version 8.0....) is showing a warning message under nuget folder in visual studio:
Package 'NServiceBus.Host 8.0.0-beta0001' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.0'. This package may not be fully compatible with your project.
Please help me to resolve this issue or point me to correct question if it's already been answered (which i could not find in SO)
NServiceBus.Host is being phased out for the reasons specified here. Long story short, in .NET Core it does not add much of a value and has more cons.
You can however, still run the NServiceBus process in a console app. Have a look at the self-hosting sample here.

Setting up unit testing for C++ in Visual Studio 2015

I'm having trouble trying to set up unit testing. My test class is very simple and looks like this:
TEST_CLASS(BlahSpec)
{
public:
TEST_METHOD(blahFunc)
{
int res = doSomething(); // this is what I'm testing
Assert::AreEqual (42, res, L"Blah", LINE_INFO());
}
};
The project compiles and runs fine. However when I choose TEST > Run > All Tests, I get the following error:
Cannot discover test extensions installed by NuGet. The NuGet service is not
available. Tests may not be found due to missing test adapter extensions
Do I have to download a NuGet package to get unit testing for C++? If so, what NuGet package should I download? I don't want any fancy third-party package, I just need the Microsoft default thing. However, the NuGet extension manager doesn't show me anything that seems to come from Microsoft.
EDIT: I've picked a NuGet package at random, NUnit3, and installed it. Now I get the following errors:
Error: Unable to get runner for this assembly. Check installation, including any extensions.
BadImageFormatException: Format of the executable (.exe) or library (.dll) is invalid.
Assembly not supported: C:\Develop\test-project\projects\Debug\UnitTestApp1\UnitTestApp1.exe
As it appears, NUnit3 does not seem the right choice for C++ native unit tests. Which NuGet package should I pick?

Visual Studio 2010 and TFS 2008: Building unit test projects

We are currently taking VS2010 for a testdrive and so far we are a little stumped with how it just won't cooperate with our existing Team Foundation Server 2008.
We still have all our projects on .NET 3.5 and whenever we are now building a solution that contains a unit test project (which automatically builds in .NET 4.0) the TFS won't build it.
The .NET 4.0 framework is installed on the TFS 2008.
The error we're receiving is:
[Any CPU/Release] c:\WINDOWS\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets(0,0): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
As a temporary workaround we are now forced to remove all our test projects in order for our solutions to build.
You need to install VS2010 on your build machine.
I'v just been trying to build V4.0 solutions on TFS2008, and altered the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\tfsbuildservice.exe.config file:
<add key="MSBuildPath" value="" />
to
<add key="MSBuildPath" value="c:\Windows\Microsoft.NET\Framework\v4.0.30319\" />
The build of v3.5 and v4.0 solutions did succeed. But the unittest of the v3.5 solutions did not work.
Read about installing VS2010 on the build server, but read somewhere else: ( http://www.richard-banks.org/2009/11/how-to-build-vs2010-solutions-using.html ) that it is possible without installing VS2010.
: Text from that website:
This worked for us allowing a TFS 2008 build agent compile VS 2010 solution/project files without installing VS 2010:
Install .NET Framework 4.0 and .NET Framework 3.51 SP1 (for some reason, SP1 wasn't included with 4.0?)
Install Windows SDK 7.0A. When I'm writing this the SDK is still not released so we had to:
From a computer with VS 2010 installed, copy the SDK folder from %programfiles%\Microsoft SDKs\Windows\v7.0A and registry settings from HKLM\SOFTWARE\Microsoft\Microsoft SDKs\Windows\7.0A to the build machine.
Copy %programfiles%\MSBuild\Microsoft\VisualStudio\v10.0 to the build machine
Change ToolsVersion from 3.5 to 4.0 in your TFSbuild.proj file.
I think that was all. There was no need to change the build agent's configuration file.
Hopefully this will work.
Install "Agents for Visual Studio 2012"
http://www.microsoft.com/en-us/download/details.aspx?id=38186