Search code examples
c++visual-studionugetnuget-packagegoogletest

Best way to add gtest to Visual Studio solution without NuGet


I have a GIT repository which contains a Visual Studio solution. I need to add some tests for the code, and wanted to use Gtest for it. Now, when I add a gtest project to the solution, a NuGet package of gtest is added to the solution directory. That's a lot of files that I don't want to keep inside the repository...

Can I add a gtest project to the solution without having to keep the package in the repository, instead linking directly to the visual studio extension? Or will I have to compile gtest myself separately and link to it manually?


Solution

  • You cannot create a GTest C++ project without using the nuget package. This is the system default project template that recommends to use Microsoft.googletest.v140.windesktop.msvcstl.static.rt-dyn nuget package.

    It is designed by Microsoft and we cannot change the project without using the nuget package. And there is no such extension we can link to.

    In fact, using the googletest nuget package is so flexible and lightweight that it can help us do other complicated work. It references the nuget packages under the solution folder. So we should not worry about missing the package.

    enter image description here

    When you get the project from the git repository into VS IDE, when you enable these two options, VS will restore the nuget package automatically when you build the project.

    enter image description here

    Besides, there is a file called <packages_id>.props in the nuget package which can import the lib and cpp files of the google test nuget package into Additional Dependencies and Include Directories automatically when you build the project. So this is also an advantage of using Nuget, you don't have to import the library manually.

    enter image description here

    As for the link you said to a particular extension, there is currently no such feature to help you create such project. Or you can download the google test source code(open source) from github website. And then let your pure c++ project(without the google test nuget package) reference the google test project. In this way, you can get what you want mostly but it is too big and complex.