使用Visual Studio构建工具构建和运行单元测试

编程入门 行业动态 更新时间:2024-10-24 18:20:49
本文介绍了使用Visual Studio构建工具构建和运行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Google Test适配器将单元测试添加到现有的C ++ Visual Studio项目中.

在使用Visual Studio 2019的计算机上,它们都运行良好,但是当我尝试在构建服务器上运行它们时,出现以下错误

错误:此项目引用了此计算机上缺少的NuGet软件包.使用NuGet软件包还原下载它们.有关更多信息,请参见

2)然后,打开构建工具,运行:

nuget restore xxx \ xxx \ xxx.sln(包含c ++项目和单元测试项目的解决方案文件的完整路径)

然后,您可以使用命令来构建项目.我希望错误会消失.

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 go.microsoft/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.

更多推荐

使用Visual Studio构建工具构建和运行单元测试

本文发布于:2023-11-17 05:05:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608933.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单元测试   工具   Visual   Studio

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!