cppunittest.h no such file or directory - c++

I try build an unit test C++ project on a CI server. On my PC no problem, but on the CI server, I have the message: "'CppUnitTest.h' : No such file or directory".
On both computer (mine and server), there is VS enterprise 2017, the only thing different it's on my PC, I build on VS, and on the CI server, I use MSBuild by command line.
I tried to include additional directories in the project as:
AdditionalIncludeDirectories: $(VCInstallDir)Auxiliary\VS\UnitTest\include;$(VCInstallDir)UnitTest\include;%(AdditionalIncludeDirectories)
AdditionalLibraryDirectories - $(VCInstallDir)UnitTest\lib;$(VCInstallDir)Auxiliary\VS\UnitTest\lib;%(AdditionalLibraryDirectories)
But it doesn't work.
Is there another directory to include ?

cppunittest.h no such file or directory
Since you have installed the Visual Studio 2017 on your build server and build the project successfully, you should use the MSBuild from the Visual Studio instead of the build tool.
You can try to call the MSBuild from following path:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe
I have create a unit test C++ project sample to test, and it works fine, if I call the MSBuild from above folder.
Hope this helps.

Related

How to run and see output after Visual Studio Solution file (.sln) has been built?

I am new to Visual Studio and CMake. I am trying to configure Insight Toolkit (ITK) in my laptop. I have done the following steps:
Downloaded the ITK Source Code from the ITK repository.
Configured and Generated Build files using CMake (Version 3.23.2)
Built Visual Studio Solution files (Visual Studio 2019)
Now I want to run a Hello World code in C++ to check everything is configured correctly. For this, I have done the following:
Created a folder named HelloWorld which contains two files
a. HelloWorld.cxx
b. CMakeLists.txt
Created another folder named HelloWorld_build, which contains CMake configuration files (executed from command prompt), and project build files (executed in Visual Studio).
Everything has run smoothly up to this point . The HelloWorld_build folder contains the HelloWorld.sln file. However, I am still not able to see the output. What is the step to see the output?

Automated unit tests build and run on commandline with Visual Studio solution

I'm working on a project with multiple Unit Tests. I have a visual studio .sln file with around 10 XXPrj in it. Those projects are made with Google Test. Everything works well if I want to run them using Visual Studio 2019, I can build and run the unit tests.
I would like to know what is the best way to run them an automated way with commandline. Purpose is to then integrate this commandline stuff in a jenkins to have everything automated.
Build
Building a Visual Studio solution/project through the command line is done with msbuild.exe. It works best to add the path of MSBuild to the PATH environment variable.
MSBuild is usually installed somewhere in the Visual Studio folders. E.g. on my machine the path is as follows:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSBuild.exe
Build the solution containing all your projects as follows:
msbuild.exe Example.sln
# Or if you want to build a release version or add additional arguments
msbuild.exe Example.sln /property:Configuration=Debug
See MSBuild CLI Docs for more options.
Side Note: Jenkins has a msbuild plugin you can use with a build step called "Build a Visual Studio project or solution using MSBuild" (Important: this does not install MSBuild, it only provides a GUI to use MSBuild in a build plan).
Run Tests
To run the tests you have two options:
Run each project's executable in your build pipeline and the executable's exit code will indicate the success/failure of the unit tests for that project. However, you will need to call each executable separately; or
Use the vstest.console.exe in combination with the Google Test Adapter
You can use the Google Test Adapter the same way in which Visual Studio uses it when you click Test -> Run -> All tests to discover & execute tests in your projects.
In my environment, vstest.console.exe is located here:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe
You also need to provide the path to the test adaptor. Then execute all the tests as follows:
# Assuming vstext.console.exe is included in the PATH
# and the current working directory is the relevant project executable
# output folder:
vstest.console.exe Project1.exe Project2.exe Project3.exe /TestAdapterPath:"<path to adapter>"
Once again the path is hidden somewhere in the Visual Studio Folders. I found it through searching for GoogleTestAdapter.TestAdapter.dll. On my machine it is located in:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\Extensions\drknwe51.xnq
Conclusion
Thus, an automated way to build and run GoogleTest unit tests, which are split over multiple projects, with the commandline can be performed in these two steps:
Build the solution/projects using msbuild.exe
Run the tests using vtest.console.exe in combination with the Google Test Adapter

VS 2015: TF900547: The directory containing the assemblies for the Visual Studio Test Runner is not valid ''

I Have VS 2015 only installed on my TFS 2013 build server, and get the following error:
TF900547: The directory containing the assemblies for the Visual Studio Test Runner is not valid ''.
Other sites say to install VS 2013, but why would I have to install VS 2013 on the build server to run unit tests when I have VS 2015 installed?
I have the following switches on my build:
/p:VisualStudioVersion=14.0 /tv:14.0
(This is not a duplicate question as I am using TFS 2013 and am trying to use the Agile Test Runner not MS Test)
Check the solution in this case:
Install VS 2015 or Microsoft Build Tools 2015.
Edit build to use a build process template called TfvcTemplate.12.xaml.
Set MSBuild arguments to /tv:14.0.
But this setting only works for build, not test. As there is no way to set the tool version or tool path for "Run VS Test Runner" activity, installing VS 2013 should be the only way to get rid of this error.
I had a similar problem - was getting the error
TF900547: The directory containing the assemblies for the Visual Studio Test Runner is not valid 'D:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow'.
It ended up being that even though Visual Studio 2015 was installed on the build agent, the user that the Build Agent was running as didn't have read/execute permissions to that folder.

building qt project using visual studio

I have build a Qt project (qwt) using the vs2013 compiler in Qt creator. When I open the .pro file and look at the build steps I see:
qmake: qmake.exe qwt.pro -r -spec win32-msvc2013
Make: nmake.exe in C:\qwt-6.1.2
When I build the project, all goes fine and the project is build without errors. So far so good.
However when I try to build this project using the command line I get errors during the nmake step. I have used the same commands as above (and I'm sure that I'm using the same versions of qmake/nmake).
...\QtCore\qglobal.h(38) : fatal error C1083: Cannot open include
file: 'stddef.h': No such file or directory
My question is, what does Qt do more so that the project does build in Qt creator and not from the command prompt? And how can I copy this behaviour in the command prompt? I'm doing this so I can make a batch file that builds the project (on a machine that does not have Qt creator installed).
In order to use the Visual Studio compilation environment from the command-line you need to call the vcvars batch script to set up the paths correctly.
Either call the vcvars64.bat in the C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\amd64 folder (that is for VS2013, you can replace the "12.0" with whatever visual studio version you have).
Or the vcvars32.bat in the C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin folder.
Or use the vcvarsall.bat x86 or vcvarsall.bat x64 calls for the script in C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
Alternatively Visual Studio creates shortcuts in the start-menu called along the lines of VS2013 x64 Native Tools Command Prompt which call those scripts.
It's likely to be that Qt Creator has added additional variables into the build environment, which are not presented when you try to compile manually through cmd.
If you look within Qt Creator under the Projects section there's Build information. Expand the Build Environment information and check to see if there's anything in there different to your machines global environment settings.

Building Visual Studio 2008 solution from command line

I'm trying to automate the building process for a certain open source project. It will do an update on the SVN directory, use CMake to get a .sln file, and build that. I can successfully do this manually, and do svn and cmake from a batch script, but Now I need to build the solution.
A quick google search revealed:
devenv /build release /project <projname> <solutionfile>.sln
However, that uses the latest version of visual studio (Visual Studio Professional 2011), while the .sln file generated is for Visual C++ Express 2008. I have both versions installed on my computer. Is there a devenv I can use for Visual C++ Express 2008? Or is there a commandline argument to specify which version to use?
UPDATE
I tried using msbuild, but that didn't seem to like building .vcproj files directly, and I didn't want to build ALL the project files by having it build the .sln file. I ended up using this:
"C:\Program Files\Microsoft Visual Studio 9.0\VC\vcpackages\vcbuild.exe" <myproj>.vcproj "Release|Win32"
I think you are using the wrong tool to build this. Rather than trying to drive the IDE from the command line you should simply use msbuild.
msbuild.exe projectname.proj /property:Configuration=Release
In order to set your environment up for the specific version of MSVC you need to call the vcvar.bat file from that specific version. This will set up the necessary environment variables needed by the build tools.
For Visual Studio Express 2008 the IDE is called VCExpress.exe. Also you should probably specify the full path of the program when you have two versions installed:
C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\VCExpress.exe /build release /project <projname> <solutionfile>.sln